Android checks when a table has been updated

Hi, I am starting to develop an Android application that will use SQLite DB, which will contain several tables. What I would like to know is when the last tables were updated, because some data does not need to be updated, say, a week, when other tables need to be updated every few hours. Trying to conserve bandwidth and create a faster application. Not sure if there is a command for this (it might seem like something cannot be found), or if I have to add a field to each table with the current time and date and use System.currentTimeMillis () to determine how long it has been.

I know that this was asked below, but they never answered it, any help would be awesome :)

Check when the latest SQLite database / table has been updated (PHP)

+5
source share
3 answers

What I know about there is no SQL function for this.

You can add a field to each record with a timestamp, and then run a query to return the last label from the table.

+3
source

A little late, but what the hell, you can also add a bunch TRIGGERto your tables and save the change table, as shown below. The last modification is recorded with the type and date + time in the table modifications. Creating TRIGGERlike this can be easily done by a simple method and called for every table created in yourSQLiteOpenHelper

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;
+7
source

,

1: sqlite trigger

2: sqlite STEP 1 ( : http://www.sqlite.org/sqlite.html)

3: , # PHP

4: php android sms-

frankenstein algo, ;-)

, , ....

-2

All Articles