问题
An iPhone application I have installed uses an SQLite database to log entries with basic INSERTS and DELETES being performed on it.
However I wish to keep a permanent log of the INSERTS made to this table, so when an INSERT occurs, I want it to be written to another table also so as to create a log.
I don't have access to the application source code in order to modify the SQL statements made, but I do have access to the SQLite database.
Can I do this with triggers? If so can somebody provide a short example.
回答1:
Never used SQLite, but here is the first link from google: http://www.sqlite.org/lang_createtrigger.html
you could write something like this probably:
CREATE TRIGGER duplicate_insert INSERT ON myTable
BEGIN
INSERT INTO myDuplicateTable
VALUES(new.Id, new.Name, new.LastModified)
END;
HTH
回答2:
Which part of the SQLite reference that you reach with Google and the search terms 'sqlite trigger' (namely SQLite Query Language: CREATE TRIGGER) are you having difficulty understanding?
CREATE TRIGGER ins_maintable AFTER INSERT ON MainTable
FOR EACH ROW BEGIN INSERT INTO LoggingTable VALUES(NEW.Column1, ...); END;
Untested code...if the syntax diagram is to be believed, both semi-colons are needed; or, at least, the one before the END is needed.
来源:https://stackoverflow.com/questions/6489234/how-to-duplicate-inserts-into-a-separate-table