mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
save game before summary (summary does UPDATE only, not INSERT)
This commit is contained in:
parent
4cfc781cd7
commit
0ed20391c3
2 changed files with 13 additions and 14 deletions
|
@ -207,20 +207,18 @@ writeBlobColumnData( const XP_U8* data, gsize len, XP_U16 strVersion, sqlite3* p
|
|||
{
|
||||
XP_LOGFF( "(col=%s)", column );
|
||||
int result;
|
||||
char buf[256];
|
||||
char* query;
|
||||
char query[256];
|
||||
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
XP_Bool newGame = -1 == curRow;
|
||||
if ( newGame ) { /* new row; need to insert blob first */
|
||||
const char* fmt = "INSERT INTO games (%s) VALUES (?)";
|
||||
snprintf( buf, sizeof(buf), fmt, column );
|
||||
query = buf;
|
||||
snprintf( query, sizeof(query), fmt, column );
|
||||
} else {
|
||||
const char* fmt = "UPDATE games SET %s=? where rowid=%lld";
|
||||
snprintf( buf, sizeof(buf), fmt, column, curRow );
|
||||
query = buf;
|
||||
snprintf( query, sizeof(query), fmt, column, curRow );
|
||||
}
|
||||
XP_LOGFF( "query: %s", query );
|
||||
|
||||
result = sqlite3_prepare_v2( pDb, query, -1, &stmt, NULL );
|
||||
assertPrintResult( pDb, result, SQLITE_OK );
|
||||
|
@ -287,7 +285,9 @@ gdb_write( XWStreamCtxt* stream, XWEnv XP_UNUSED(xwe), void* closure )
|
|||
|
||||
if ( newGame ) { /* new row; need to insert blob first */
|
||||
cGlobals->rowid = selRow;
|
||||
XP_LOGFF( "new game at row %lld", selRow );
|
||||
const CurGameInfo* gi = cGlobals->gi;
|
||||
XP_U32 gameID = gi->gameID;
|
||||
XP_LOGFF( "new game for id %d at row %lld", gameID, selRow );
|
||||
} else {
|
||||
assert( selRow == cGlobals->rowid );
|
||||
}
|
||||
|
@ -434,6 +434,7 @@ gdb_summarize( CommonGlobals* cGlobals )
|
|||
for ( int ii = 0; !!pairs[ii]; ++ii ) {
|
||||
g_free( pairs[ii] );
|
||||
}
|
||||
XP_ASSERT( -1 != cGlobals->rowid );
|
||||
gchar* query = g_strdup_printf( "UPDATE games SET %s WHERE rowid=%lld",
|
||||
vals, cGlobals->rowid );
|
||||
g_free( vals );
|
||||
|
|
|
@ -458,13 +458,8 @@ linuxSaveGame( CommonGlobals* cGlobals )
|
|||
}
|
||||
|
||||
if ( doSave ) {
|
||||
if ( !!pDb ) {
|
||||
gdb_summarize( cGlobals );
|
||||
}
|
||||
|
||||
XWStreamCtxt* outStream;
|
||||
MemStreamCloseCallback onClose = !!pDb? gdb_write : writeToFile;
|
||||
outStream =
|
||||
XWStreamCtxt* outStream =
|
||||
mem_stream_make_sized( MPPARM(cGlobals->util->mpool)
|
||||
cGlobals->params->vtMgr,
|
||||
cGlobals->lastStreamSize,
|
||||
|
@ -477,8 +472,11 @@ linuxSaveGame( CommonGlobals* cGlobals )
|
|||
stream_destroy( outStream, NULL_XWE );
|
||||
|
||||
game_saveSucceeded( &cGlobals->game, NULL_XWE, cGlobals->curSaveToken );
|
||||
XP_LOGF( "%s: saved", __func__ );
|
||||
|
||||
if ( !!pDb ) {
|
||||
gdb_summarize( cGlobals );
|
||||
}
|
||||
XP_LOGF( "%s: saved", __func__ );
|
||||
} else {
|
||||
XP_LOGF( "%s: simulating save failure", __func__ );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue