SA-MP Forums Archive
Converting this to threaded mysql? Getting value. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Converting this to threaded mysql? Getting value. (/showthread.php?tid=585112)



Converting this to threaded mysql? Getting value. - Dokins - 10.08.2015

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;
}



Re: Converting this to threaded mysql? Getting value. - Jefff - 11.08.2015

Maybe try

return cache_get_row_int(0, 0);

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


Re: Converting this to threaded mysql? Getting value. - Dokins - 11.08.2015

Thanks a lot man, will do that.


Re: Converting this to threaded mysql? Getting value. - Evocator - 11.08.2015

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;
}



Re: Converting this to threaded mysql? Getting value. - Dokins - 11.08.2015

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