SQLiteCpp icon indicating copy to clipboard operation
SQLiteCpp copied to clipboard

how to detect change or udpate column in table

Open bnadem opened this issue 6 years ago • 1 comments

i want to fire event after change or update column in table sqlite3_update_hook , is any solution please thanks

bnadem avatar Nov 26 '19 15:11 bnadem

@bnadem Can you elaborate on your requirements? It sounds like you want a trigger, which could be implemented via calling db.exec() on at CREATE TRIGGER sqlite statement.

An example CREATE TRIGGER statement might look like this:

CREATE TRIGGER add_change_to_foo_audit_log
   AFTER UPDATE ON list_of_foos
   WHEN old.foo_col <> new.foo_col
      
BEGIN
    INSERT INTO foo_audit_log (
        old_id,
        new_id,
        old_foo_col,
        new_foo_col,
        created_at
    )
VALUES
    (
        old.id,
        new.id,
        old.foo_col,
        new.foo_col,
        DATETIME('NOW')
    ) ;
END;

Then you would call db.exec() to execute it on the database.

ptrks avatar Dec 23 '19 19:12 ptrks