set new clntvers row in devices table at the same time as updating it

in games table.  (The latter is now redundant and will go away.)
This commit is contained in:
Eric House 2013-08-21 06:49:37 -07:00
parent f728f7459b
commit 3dee41e584

View file

@ -460,26 +460,26 @@ DBMgr::AddDevice( const char* connName, HostID curID, int clientVersion,
} }
assert( newID <= 4 ); assert( newID <= 4 );
string devIDBuf; string query;
string_printf( query, "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d,"
" clntVers[%d] = %d, seeds[%d] = %d, addrs[%d] = \'%s\', ",
newID, nToAdd, newID, clientVersion, newID, seed, newID,
inet_ntoa( addr->sin_addr() ) );
if ( DEVID_NONE != devID ) { if ( DEVID_NONE != devID ) {
string_printf( devIDBuf, "devids[%d] = %d, ", newID, devID ); string_printf( query, "devids[%d] = %d, ", newID, devID );
} else { }
assert( 0 == strlen(devIDBuf.c_str()) ); string_printf( query, " tokens[%d] = %d, mtimes[%d]='now', ack[%d]=\'%c\'"
" WHERE connName = '%s'", newID, addr->clientToken(),
newID, newID, ackd?'A':'a', connName );
// Update the devices table too. Eventually the clntVers field of the
// games table should go away.
if ( DEVID_NONE != devID ) {
string_printf( query, "; UPDATE " DEVICES_TABLE " SET clntVers = %d"
" WHERE id = %d", clientVersion, devID );
} }
const char* fmt = "UPDATE " GAMES_TABLE " SET nPerDevice[%d] = %d,"
" clntVers[%d] = %d,"
" seeds[%d] = %d, addrs[%d] = \'%s\', %s"
" tokens[%d] = %d, mtimes[%d]='now', ack[%d]=\'%c\'"
" WHERE connName = '%s'";
string query;
char* ntoa = inet_ntoa( addr->sin_addr() );
string_printf( query, fmt, newID, nToAdd, newID, clientVersion,
newID, seed, newID, ntoa, devIDBuf.c_str(),
newID, addr->clientToken(), newID, newID, ackd?'A':'a',
connName );
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() ); logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
execSql( query ); execSql( query );
return newID; return newID;