From 465370bac6c6eb642817454b06090c4961e5d8d7 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 14 Jan 2011 19:03:08 -0800 Subject: [PATCH] add ctime and mtime timestamps to DB when creating, and upgrade to new version by adding them. Can't have them default to 'now' because that's not supported for ADDs. Can't remove columns either, so at some point I'll need to migrate to get rid of accumulated cruft. Timestamps are not set nor read yet. --- .../src/org/eehouse/android/xw4/DBHelper.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java index 5e34e8c6a..515e02aa1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java @@ -29,7 +29,7 @@ public class DBHelper extends SQLiteOpenHelper { public static final String TABLE_NAME_SUM = "summaries"; public static final String TABLE_NAME_OBITS = "obits"; private static final String DB_NAME = "xwdb"; - private static final int DB_VERSION = 6; + private static final int DB_VERSION = 7; public static final String FILE_NAME = "FILE_NAME"; public static final String NUM_MOVES = "NUM_MOVES"; @@ -52,9 +52,10 @@ public class DBHelper extends SQLiteOpenHelper { public static final String SEED = "SEED"; public static final String SMSPHONE = "SMSPHONE"; // not used yet - public static final String CREATE_TIME = "CREATE_TIME"; + // public static final String CREATE_TIME = "CREATE_TIME"; + public static final String CTIME = "CTIME"; // not used yet - public static final String LASTPLAY_TIME = "LASTPLAY_TIME"; + public static final String MTIME = "MTIME"; public DBHelper( Context context ) @@ -85,8 +86,11 @@ public class DBHelper extends SQLiteOpenHelper { // HASMSGS: sqlite doesn't have bool; use 0 and 1 + HASMSGS + " INTEGER DEFAULT 0," - + CREATE_TIME + " INTEGER," - + LASTPLAY_TIME + " INTEGER," + + CTIME + " TIMESTAMP," + + MTIME + " TIMESTAMP," + + // + CREATE_TIME + " INTEGER," + // + LASTPLAY_TIME + " INTEGER," + SNAPSHOT + " BLOB" + ");" ); @@ -112,8 +116,24 @@ public class DBHelper extends SQLiteOpenHelper { { Utils.logf( "onUpgrade: old: %d; new: %d", oldVersion, newVersion ); - if ( newVersion == 6 && oldVersion == 5 ) { - onCreateObits(db); + if ( newVersion == 7 ) { + switch( oldVersion ) { + case 5: + onCreateObits( db ); + // FALLTHRU + case 6: + // F*cking sqlite won't let me add a column with a + // non-constant default (i.e. DEFAULT + // (datetime('now','localtime'))," so I'll have to add + // the value manually. Or screw everybody and nuke + // the DB rather than modify it. I want my + // postgres... + db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM + + " ADD " + CTIME + " TIMESTAMP;" ); + db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM + + " ADD " + MTIME + " TIMESTAMP;" ); + break; + } } else { db.execSQL( "DROP TABLE " + TABLE_NAME_SUM + ";" ); if ( oldVersion >= 6 ) {