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 so开发者_StackOverflow中文版mebody provide a short example.
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
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.
精彩评论