diff --git a/xwords4/relay/dbmgr.cpp b/xwords4/relay/dbmgr.cpp index c269bd638..1bdec963c 100644 --- a/xwords4/relay/dbmgr.cpp +++ b/xwords4/relay/dbmgr.cpp @@ -457,7 +457,8 @@ DBMgr::ReregisterDevice( DevIDRelay relayID, const DevID* host, .appendParam( host->m_devIDType ) .appendParam( host->m_devIDString.c_str() ); - formatUpdate( qb, true, desc, clientVersion, model, osVers, variant, relayID ); + formatUpdate( qb, true, desc, clientVersion, model, osVers, variant, relayID, + host->m_devIDString.c_str() ); qb.finish(); execParams( qb ); } @@ -480,7 +481,7 @@ DBMgr::UpdateDevice( DevIDRelay relayID, const char* const desc, QueryBuilder qb; qb.appendQueryf( "UPDATE " DEVICES_TABLE " SET " ); formatUpdate( qb, false, desc, clientVersion, model, osVers, - variant, relayID ); + variant, relayID, NULL ); qb.finish(); execParams( qb ); } @@ -498,7 +499,7 @@ DBMgr::formatUpdate( QueryBuilder& qb, bool append, const char* const desc, int clientVersion, const char* const model, const char* const osVers, const char* const variant, - DevIDRelay relayID ) + DevIDRelay relayID, const char* newDevID ) { if ( append ) { qb.appendQueryf( "mtimes=array_prepend('now', mtimes)" ); // FIXME: too many @@ -524,8 +525,15 @@ DBMgr::formatUpdate( QueryBuilder& qb, qb.appendQueryf( ", variant=$$" ) .appendParam( variant ); } + qb.appendQueryf( " WHERE id = $$" ) .appendParam( relayID ); + + if ( !!newDevID ) { + assert( append ); + qb.appendQueryf( " AND NOT devids[1] = $$" ) + .appendParam( newDevID ); + } } HostID diff --git a/xwords4/relay/dbmgr.h b/xwords4/relay/dbmgr.h index 74aa347bc..51fcb76ab 100644 --- a/xwords4/relay/dbmgr.h +++ b/xwords4/relay/dbmgr.h @@ -177,7 +177,7 @@ class DBMgr { void formatUpdate( QueryBuilder& qb, bool append, const char* const desc, int clientVersion, const char* const model, const char* const osVers, const char* const variant, - DevIDRelay relayID ); + DevIDRelay relayID, const char* newDevID ); PGconn* getThreadConn( void ); diff --git a/xwords4/relay/scripts/showinplay.sh b/xwords4/relay/scripts/showinplay.sh index 51e7c6ca3..ac367091b 100755 --- a/xwords4/relay/scripts/showinplay.sh +++ b/xwords4/relay/scripts/showinplay.sh @@ -67,7 +67,7 @@ echo "SELECT id,connName,hid as h,token,ctime,stime,devid,msg64 "\ | psql xwgames # Devices -LINE="SELECT id, model, osvers, array_length(mtimes, 1) as mcnt, mtimes[1] as mtime, array_length(devTypes, 1) as dcnt, devTypes[1] as dTyp, devids[1] as devid FROM devices " +LINE="SELECT id, model, osvers, array_length(mtimes, 1) as mcnt, mtimes[1] as mtime, array_length(devTypes, 1) as dcnt, devTypes as dTyps, devids[1] as devid_1 FROM devices " if [ -n "$FILTER_DEVS" ]; then LINE="${LINE} WHERE id IN (select UNNEST(devids) FROM games $QUERY)" fi