add modified trigger

This commit is contained in:
Andrew Dolgov 2011-12-06 12:38:08 +03:00
parent 815e40a698
commit d4b6e34b98

View File

@ -9,7 +9,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
public static final String DATABASE_NAME = "OfflineStorage.db"; public static final String DATABASE_NAME = "OfflineStorage.db";
public static final int DATABASE_VERSION = 1; public static final int DATABASE_VERSION = 2;
public DatabaseHelper(Context context) { public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION); super(context, DATABASE_NAME, null, DATABASE_VERSION);
@ -20,6 +20,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
db.execSQL("DROP TABLE IF EXISTS feeds;"); db.execSQL("DROP TABLE IF EXISTS feeds;");
db.execSQL("DROP TABLE IF EXISTS articles;"); db.execSQL("DROP TABLE IF EXISTS articles;");
db.execSQL("DROP VIEW IF EXISTS feeds_unread;"); db.execSQL("DROP VIEW IF EXISTS feeds_unread;");
db.execSQL("DROP TRIGGER IF EXISTS articles_set_modified;");
db.execSQL("CREATE TABLE IF NOT EXISTS feeds (" + db.execSQL("CREATE TABLE IF NOT EXISTS feeds (" +
BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
@ -40,10 +41,16 @@ public class DatabaseHelper extends SQLiteOpenHelper {
"link TEXT, " + "link TEXT, " +
"feed_id INTEGER, " + "feed_id INTEGER, " +
"tags TEXT, " + "tags TEXT, " +
"content TEXT," + "content TEXT, " +
"selected BOOLEAN" + "selected BOOLEAN, " +
"modified BOOLEAN" +
");"); ");");
db.execSQL("CREATE TRIGGER articles_set_modified UPDATE OF marked, published, unread ON articles " +
"BEGIN " +
" UPDATE articles SET modified = 1 WHERE " + BaseColumns._ID + " = " + "OLD." + BaseColumns._ID + "; " +
"END;");
db.execSQL("CREATE VIEW feeds_unread AS SELECT feeds."+BaseColumns._ID+" AS "+BaseColumns._ID+", " + db.execSQL("CREATE VIEW feeds_unread AS SELECT feeds."+BaseColumns._ID+" AS "+BaseColumns._ID+", " +
"feeds.title AS title, " + "feeds.title AS title, " +
"SUM(articles.unread) AS unread FROM feeds " + "SUM(articles.unread) AS unread FROM feeds " +