SQLite Tutorial
|
|
|
|
| Articles Reviews Structured Query Language | |
| Written by Mike Chirico | |
| Monday, 27 November 2006 | |
|
Page 2 of 12 Logging All Inserts, Updates, and Deletes The script below creates the table examlog and three triggers (update_examlog, insert_examlog, and delete_examlog) to record updates, inserts, and deletes made to the exam table. In other words, whenever a change is made to the exam table, the changes will be recorded in the examlog table, including the old value and the new value. If you are familiar with MySQL, the functionality of this log table is similar to MySQL's binlog. See Tips 2, 24, and 25 if you would like more information on MySQL's log file. -- ******************************************************************* Since the script above has been created in the file examLOG, you can execute the commands in sqlite3 as shown below. Also shown below is a record insert, and an update to test these newly-created triggers. $ sqlite3 examdatabase < examLOG Now, by doing the select statement below, you will see that examlog contains an entry for the insert statement, plus two updates. Although we only did one update on the commandline, the trigger "insert_exam_timeEnter" performed an update for the field timeEnter; this was the trigger defined in "examScript". In the second update, we can see that the score has been changed. The trigger is working. Any change made to the table, whether by user interaction or another trigger, is recorded in the examlog. $ sqlite3 examdatabase "select * from examlog" Again, pay particular attention to the AFTER keyword. Remember that by default, triggers are BEFORE, so you must specify AFTER to insure that all new values will be available if your trigger needs to work with any new values. |
|
| Last Updated ( Sunday, 06 January 2008 ) | |
| < Prev | Next > |
|---|







