sqldata/sqlpgapi.cpp
// Execute the statement and get scalar result
Execute the statement and get scalar result
Execute the statement and get scalar result
int SqlPgApi::ExecuteScalar(const char *query, int *result, size_t *time_spent)
{
	if(query == NULL || result == NULL)
		return -1;
	size_t start = Os::GetTickCount();
	PGresult *res = _PQexec(_conn, query);
	bool exists = false;
	if(_PQresultStatus(res) == PGRES_TUPLES_OK)
	{
		char *value = _PQgetvalue(res, 0, 0);
		sscanf(value, "%d", result);
		exists = true;
	}
	else
		SetError();
	_PQclear(res);
	if(time_spent != NULL)
		*time_spent = Os::GetTickCount() - start;
	return (exists == true) ? 0 : -1;
}
int SqlPgApi :: ExecuteScalar ( const char * query , int * result , size_t * time_spent ) { if ( query == NULL || result == NULL ) return -1 ; size_t start = Os :: GetTickCount ( ) ; PGresult * res = _PQexec ( _conn , query ) ; bool exists = false ; if ( _PQresultStatus ( res ) == PGRES_TUPLES_OK ) { char * value = _PQgetvalue ( res , 0 , 0 ) ; sscanf ( value , " " , result ) ; exists = true ; } else SetError ( ) ; _PQclear ( res ) ; if ( time_spent != NULL ) * time_spent = Os :: GetTickCount ( ) - start ; return ( exists == true ) ? 0 : -1 ; }
Execute the statement and get scalar result
Execute the statement and get scalar result
// Execute the statement // Get the value of the first column of the first row