simplify construction of one query

This commit is contained in:
Eric House 2013-10-09 21:13:22 -07:00
parent becbf7aea6
commit 9efb044c4f

View file

@ -396,32 +396,18 @@ DBMgr::RegisterDevice( const DevID* host, int clientVersion,
devID = (DevIDRelay)random(); devID = (DevIDRelay)random();
} while ( DEVID_NONE == devID ); } while ( DEVID_NONE == devID );
const char* command = "INSERT INTO " DEVICES_TABLE StrWPF query;
" (id, devTypes[1], devids[1], clntVers, versDesc, model, osvers)" query.catf( "INSERT INTO " DEVICES_TABLE " (id, devTypes[1],"
" VALUES( $1, $2, $3, $4, $5, $6, $7 )"; " devids[1], clntVers, versdesc, model, osvers)"
int nParams = 7; " VALUES( %d, %d, '%s', %d, '%s', '%s', '%s' )",
char* paramValues[nParams]; devID, host->m_devIDType, devidStr, clientVersion,
char buf[1024]; desc, model, osVers );
formatParams( paramValues, nParams, logf( XW_LOGINFO, "%s: %s", __func__, query.c_str() );
"%d"DELIM"%d"DELIM"%s"DELIM"%d"DELIM"%s"DELIM"%s"DELIM"%s", success = execSql( query );
buf, sizeof(buf), devID, host->m_devIDType,
devidStr, clientVersion, desc, model, osVers );
PGresult* result = PQexecParams( getThreadConn(), command,
nParams, NULL,
paramValues,
NULL, NULL, 0 );
success = PGRES_COMMAND_OK == PQresultStatus(result);
if ( !success ) {
logf( XW_LOGERROR, "%s: PQexec=>%s;%s", __func__,
PQresStatus(PQresultStatus(result)),
PQresultErrorMessage(result) );
}
PQclear( result );
} }
} }
return devID; return devID;
} } // RegisterDevice
DevIDRelay DevIDRelay
DBMgr::RegisterDevice( const DevID* host ) DBMgr::RegisterDevice( const DevID* host )