有点晚了,但到底是什么——你也可以在你的表上放一堆TRIGGER
s 并维护一个修改表,如下所示。最近的修改以类型和日期+时间记录在modifications
表中。TRIGGER
可以通过一个简单的方法轻松完成创建这样的 s,并为您在您的文件中创建的每个表调用SQLiteOpenHelper
CREATE TABLE table1 (
_id INTEGER PRIMARY KEY AUTOINCREMENT,
text1 TEXT,
text2 TEXT
);
CREATE TABLE table2 (
_id INTEGER PRIMARY KEY AUTOINCREMENT,
text1 TEXT,
int1 INTEGER
);
CREATE TABLE modifications (
table_name TEXT NOT NULL PRIMARY KEY ON CONFLICT REPLACE,
action TEXT NOT NULL,
changed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TRIGGER IF NOT EXISTS table1_ondelete AFTER DELETE ON table1
BEGIN
INSERT INTO modifications (table_name, action) VALUES ('table1','DELETE');
END;
CREATE TRIGGER IF NOT EXISTS table2_ondelete AFTER DELETE ON table2
BEGIN
INSERT INTO modifications (table_name, action) VALUES ('table2','DELETE');
END;
CREATE TRIGGER IF NOT EXISTS table1_onupdate AFTER UPDATE ON table1
BEGIN
INSERT INTO modifications (table_name, action) VALUES ('table1','UPDATE');
END;
CREATE TRIGGER IF NOT EXISTS table2_onupdate AFTER UPDATE ON table2
BEGIN
INSERT INTO modifications (table_name, action) VALUES ('table2','UPDATE');
END;
CREATE TRIGGER IF NOT EXISTS table1_oninsert AFTER INSERT ON table1
BEGIN
INSERT INTO modifications (table_name, action) VALUES ('table1','INSERT');
END;
CREATE TRIGGER IF NOT EXISTS table2_oninsert AFTER INSERT ON table2
BEGIN
INSERT INTO modifications (table_name, action) VALUES ('table2','INSERT');
END;