in devices table, replace devid and devtype with array so can track

history if/as they change; remove rrcount as no longer needed.
This commit is contained in:
Eric House 2013-09-15 09:59:51 -07:00
parent 3499af3ac4
commit de1f1cf681
2 changed files with 6 additions and 6 deletions

View file

@ -395,7 +395,7 @@ DBMgr::RegisterDevice( const DevID* host, int clientVersion,
} while ( DEVID_NONE == devID );
const char* command = "INSERT INTO " DEVICES_TABLE
" (id, devType, devid, clntVers, versDesc, model, osvers)"
" (id, devTypes[1], devids[1], clntVers, versDesc, model, osvers)"
" VALUES( $1, $2, $3, $4, $5, $6, $7 )";
int nParams = 7;
char* paramValues[nParams];
@ -435,7 +435,8 @@ DBMgr::ReregisterDevice( DevIDRelay relayID, const DevID* host,
// First update the existing
StrWPF query;
query.printf( "UPDATE " DEVICES_TABLE " SET "
"rrcount = rrcount + 1, devType = %d, devid = '%s', ",
"devTypes = array_prepend( %d, devTypes), "
"devids = array_prepend('%s', devids), ",
host->m_devIDType, host->m_devIDString.c_str() );
formatUpdate( query, desc, clientVersion, model, osVers, relayID );
@ -888,7 +889,7 @@ DBMgr::getDevID( const DevID* devID )
}
} else if ( 0 < devID->m_devIDString.size() ) {
query.printf( "SELECT id FROM " DEVICES_TABLE
" WHERE devtype=%d and devid = '%s'"
" WHERE devtypes[1]=%d and devids[1] = '%s'"
" ORDER BY ctime DESC LIMIT 1",
devIDType, devID->m_devIDString.c_str() );
}

View file

@ -81,11 +81,10 @@ EOF
cat | psql $DBNAME --file - <<EOF
CREATE TABLE devices (
id INTEGER UNIQUE PRIMARY KEY
,devType INTEGER
,devTypes INTEGER[]
,devids TEXT[]
,clntVers INTEGER
,rrcount INTEGER DEFAULT 0
,versDesc TEXT
,devid TEXT
,model TEXT
,osvers TEXT
,ctime TIMESTAMP DEFAULT CURRENT_TIMESTAMP