get rid of stringstream where it wasn't working (maybe because of user

error -- whatever); fix error check to avoid false conclusion that
query didn't work so that update of num bytes sent in background works.
This commit is contained in:
Andy2 2011-09-30 18:20:28 -07:00
parent 22382b3a19
commit 28e5c39845

View file

@ -400,24 +400,24 @@ void
DBMgr::RecordSent( const int* msgIDs, int nMsgIDs ) DBMgr::RecordSent( const int* msgIDs, int nMsgIDs )
{ {
if ( nMsgIDs > 0 ) { if ( nMsgIDs > 0 ) {
stringstream buf; char buf[1024];
buf << "SELECT connname, hid, sum(msglen) FROM " MSGS_TABLE unsigned int offset = 0;
" WHERE id IN ("; offset = snprintf( buf, sizeof(buf), "SELECT connname,hid,sum(msglen)"
" FROM " MSGS_TABLE " WHERE id IN (" );
for ( int ii = 0; ; ) { for ( int ii = 0; ; ) {
buf << msgIDs[ii]; offset += snprintf( &buf[offset], sizeof(buf) - offset, "%d,",
msgIDs[ii] );
assert( offset < sizeof(buf) );
if ( ++ii == nMsgIDs ) { if ( ++ii == nMsgIDs ) {
--offset; /* back over comma */
break; break;
} }
buf << ',';
} }
buf << ") GROUP BY connname,hid"; offset += snprintf( &buf[offset], sizeof(buf) - offset,
") GROUP BY connname,hid" );
const char* query = buf.str().c_str(); PGresult* result = PQexec( getThreadConn(), buf );
logf( XW_LOGINFO, "%s: query: %s", __func__, query ); if ( PGRES_TUPLES_OK == PQresultStatus( result ) ) {
PGresult* result = PQexec( getThreadConn(), query );
if ( PGRES_COMMAND_OK == PQresultStatus( result ) ) {
int ntuples = PQntuples( result ); int ntuples = PQntuples( result );
for ( int ii = 0; ii < ntuples; ++ii ) { for ( int ii = 0; ii < ntuples; ++ii ) {
RecordSent( PQgetvalue( result, ii, 0 ), RecordSent( PQgetvalue( result, ii, 0 ),