Converting this to threaded mysql? Getting value.
#1

Title says all. I'm trying to get the correct value but it always returns 0.

pawn Код:
MySQL_GetValue(sqlid, fieldname[], tablename[])
{
    new query[256];
    format(query, sizeof(query), "SELECT %s FROM %s WHERE id = %d LIMIT 1", fieldname, tablename, sqlid);
    mysql_tquery(dbHandle, query, "GetValue", "");
}
forward GetValue();
public GetValue()
{
    new temp[64];
    cache_get_row(0,0, temp);
    new result = strval(temp);
    return result;
}
Reply
#2

Maybe try

return cache_get_row_int(0, 0);

or add debug info
if(!cache_num_rows()) print("Not found");
Reply
#3

Thanks a lot man, will do that.
Reply
#4

Please note that MySQL_GetValue will no return the value since the query is threaded.
A normal (which i dont recommend) would look like this and work:

Код:
MySQL_GetValue(sqlid, fieldname[], tablename[])
{
	new 
		Query[128];

	mysql_format(g_SQL, Query, sizeof (Query), "SELECT `%e` FROM `%e` WHERE `id` = '%i' LIMIT 1", fieldname, tablename, sqlid);

	new 
		Cache:result = mysql_query(g_SQL, Query),
		value
	;

	if (!cache_num_rows()) {
		return 0;
	}

	value = cache_get_field_content_int(0, fieldname);
	cache_delete(result);

	return value;
}
Reply
#5

Thanks man, I really appreciate it. Sorry for the delay.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)