mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
toward having game deletion get reported even if network isn't live at
the moment: create new "obits" table and put dead game info in it. Change constant for current table name to be less generic.
This commit is contained in:
parent
2127394260
commit
111c59dd30
3 changed files with 66 additions and 20 deletions
|
@ -26,9 +26,10 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
|
||||
public class DBHelper extends SQLiteOpenHelper {
|
||||
|
||||
public static final String TABLE_NAME = "summaries";
|
||||
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 = 5;
|
||||
private static final int DB_VERSION = 6;
|
||||
|
||||
public static final String FILE_NAME = "FILE_NAME";
|
||||
public static final String NUM_MOVES = "NUM_MOVES";
|
||||
|
@ -61,10 +62,9 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
super( context, DB_NAME, null, DB_VERSION );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate( SQLiteDatabase db )
|
||||
private void onCreateSum( SQLiteDatabase db )
|
||||
{
|
||||
db.execSQL( "CREATE TABLE " + TABLE_NAME + " ("
|
||||
db.execSQL( "CREATE TABLE " + TABLE_NAME_SUM + " ("
|
||||
+ FILE_NAME + " TEXT PRIMARY KEY,"
|
||||
+ NUM_MOVES + " INTEGER,"
|
||||
+ NUM_PLAYERS + " INTEGER,"
|
||||
|
@ -92,11 +92,34 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
+ ");" );
|
||||
}
|
||||
|
||||
private void onCreateObits( SQLiteDatabase db )
|
||||
{
|
||||
db.execSQL( "CREATE TABLE " + TABLE_NAME_OBITS + " ("
|
||||
+ RELAYID + " TEXT,"
|
||||
+ SEED + " INTEGER"
|
||||
+ ");" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate( SQLiteDatabase db )
|
||||
{
|
||||
onCreateSum( db );
|
||||
onCreateObits( db );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade( SQLiteDatabase db, int oldVersion, int newVersion )
|
||||
{
|
||||
Utils.logf( "onUpgrade: old: %d; new: %d", oldVersion, newVersion );
|
||||
db.execSQL( "DROP TABLE " + TABLE_NAME + ";" );
|
||||
|
||||
if ( newVersion == 6 && oldVersion == 5 ) {
|
||||
onCreateObits(db);
|
||||
} else {
|
||||
db.execSQL( "DROP TABLE " + TABLE_NAME_SUM + ";" );
|
||||
if ( oldVersion >= 6 ) {
|
||||
db.execSQL( "DROP TABLE " + TABLE_NAME_OBITS + ";" );
|
||||
}
|
||||
onCreate( db );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ public class DBUtils {
|
|||
};
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + file + "\"";
|
||||
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME, columns, selection,
|
||||
null, null, null, null );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
summary = new GameSummary();
|
||||
summary.nMoves = cursor.getInt(cursor.
|
||||
|
@ -139,7 +139,7 @@ public class DBUtils {
|
|||
|
||||
if ( null == summary ) {
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
db.delete( DBHelper.TABLE_NAME, selection, null );
|
||||
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.FILE_NAME, path );
|
||||
|
@ -171,8 +171,8 @@ public class DBUtils {
|
|||
Utils.logf( "saveSummary: nMoves=%d", summary.nMoves );
|
||||
|
||||
try {
|
||||
long result = db.replaceOrThrow( DBHelper.TABLE_NAME, "",
|
||||
values );
|
||||
long result = db.replaceOrThrow( DBHelper.TABLE_NAME_SUM,
|
||||
"", values );
|
||||
} catch ( Exception ex ) {
|
||||
Utils.logf( "ex: %s", ex.toString() );
|
||||
}
|
||||
|
@ -191,8 +191,8 @@ public class DBUtils {
|
|||
+ dict + "\'";
|
||||
// null for columns will return whole rows: bad
|
||||
String[] columns = { DBHelper.DICTNAME };
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME, columns, selection,
|
||||
null, null, null, null );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
|
||||
result = cursor.getCount();
|
||||
cursor.close();
|
||||
|
@ -207,7 +207,8 @@ public class DBUtils {
|
|||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
String cmd = String.format( "UPDATE %s SET %s = 1 WHERE %s = '%s'",
|
||||
DBHelper.TABLE_NAME, DBHelper.HASMSGS,
|
||||
DBHelper.TABLE_NAME_SUM,
|
||||
DBHelper.HASMSGS,
|
||||
DBHelper.RELAYID, relayID );
|
||||
db.execSQL( cmd );
|
||||
db.close();
|
||||
|
@ -222,8 +223,8 @@ public class DBUtils {
|
|||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.FILE_NAME };
|
||||
String selection = DBHelper.RELAYID + "='" + relayID + "'";
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME, columns, selection,
|
||||
null, null, null, null );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
result = cursor.getString( cursor
|
||||
.getColumnIndex(DBHelper.FILE_NAME));
|
||||
|
@ -247,8 +248,8 @@ public class DBUtils {
|
|||
String selection = DBHelper.RELAYID + " NOT null AND "
|
||||
+ "NOT " + DBHelper.HASMSGS;
|
||||
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME, columns, selection,
|
||||
null, null, null, null );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
|
||||
if ( 0 < cursor.getCount() ) {
|
||||
cursor.moveToFirst();
|
||||
|
@ -272,6 +273,27 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void addDeceased( Context context, String relayID,
|
||||
int seed )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.RELAYID, relayID );
|
||||
values.put( DBHelper.SEED, seed );
|
||||
|
||||
try {
|
||||
long result = db.replaceOrThrow( DBHelper.TABLE_NAME_OBITS,
|
||||
"", values );
|
||||
} catch ( Exception ex ) {
|
||||
Utils.logf( "ex: %s", ex.toString() );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static void initDB( Context context )
|
||||
{
|
||||
if ( null == s_dbHelper ) {
|
||||
|
|
|
@ -475,7 +475,8 @@ public class GameUtils {
|
|||
{
|
||||
GameSummary summary = DBUtils.getSummary( context, path );
|
||||
if ( null != summary.relayID ) {
|
||||
NetUtils.informOfDeath( context, summary.relayID, summary.seed );
|
||||
DBUtils.addDeceased( context, summary.relayID, summary.seed );
|
||||
// NetUtils.informOfDeath( context, summary.relayID, summary.seed );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue