sqldata/sqlmysqlapi.cpp
// Execute the statement and get scalar result
Execute the statement and get scalar result
Execute the statement and get scalar result
int SqlMysqlApi::ExecuteScalar(const char *query, int *result, size_t *time_spent)
{
	if(query == NULL || result == NULL)
		return -1;
	size_t start = Os::GetTickCount();
	int rc = _mysql_query(&_mysql, query);
	if(rc != 0)
	{
		SetError();
		return -1;
	}
	MYSQL_RES *res = _mysql_use_result(&_mysql);
	if(result == NULL)
		return -1;
	bool exists = false;
	MYSQL_ROW row = _mysql_fetch_row(res);
	if(row != NULL && row[0] != NULL)
	{
		sscanf(row[0], "%d", result);
		exists = true;
	}
	_mysql_free_result(res);
	if(time_spent != NULL)
		*time_spent = Os::GetTickCount() - start;
	return (exists == true) ? 0 : -1;
}
int SqlMysqlApi :: ExecuteScalar ( const char * query , int * result , size_t * time_spent ) { if ( query == NULL || result == NULL ) return -1 ; size_t start = Os :: GetTickCount ( ) ; int rc = _mysql_query ( & _mysql , query ) ; if ( rc != 0 ) { SetError ( ) ; return -1 ; } MYSQL_RES * res = _mysql_use_result ( & _mysql ) ; if ( result == NULL ) return -1 ; bool exists = false ; MYSQL_ROW row = _mysql_fetch_row ( res ) ; if ( row != NULL && row [ 0 ] != NULL ) { sscanf ( row [ 0 ] , " " , result ) ; exists = true ; } _mysql_free_result ( 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 query // Error raised // Fetch the first row