View Single Post
Old 13/08/2012, 08:49 PM   #2719
AndreT's Avatar
Join Date: Jul 2011
Posts: 966
Reputation: 414
Default Re: [REL] MySQL Plugin (R7 released)

I cannot see an obvious mistake there, perhaps it is because it is already quite late and I've been trying out stuff in C++ for the past few hours. But yes, the design is to debug like that, the debug message looks fine to me as well. So question: is mysql_logreg fired?

On a side note, cache_get_row_int(row, index)
I have been fiddling around with the plugin code numerous times in the past, but today, as I was styling up my gamemode's MySQL-related functions, I thought of creating a function that would return an integer instead of storing a string.

// native cache_get_row_int(row, idx, connectionHandle = 1);
cell AMX_NATIVE_CALL Natives::n_cache_get_row_int(AMX* amx, cell* params)
	unsigned int cID = params[3] - 1;
	VALID_CONNECTION_HANDLE("cache_get_row_int", cID);
	CMySQLHandler *cHandle = SQLHandle[cID];

	unsigned int a = params[1];
	if(a > cHandle->m_sCache.size())
		return 0;

	int val = atoi(cHandle->m_sCache[a][params[2]]);

	return val;
This is what I came up with in C++. Now I am not advanced in the language in any way (as some might already notice from a short read), but I followed the syntax of other natives in CScripting.cpp.

This also requires that you modify the Natives class in CScripting.h and add the line:
class Natives
    // ...
    static cell AMX_NATIVE_CALL n_cache_get_row_int(AMX* amx, cell* params);
    // ...
and also register the native for AMX in main.cpp:
const AMX_NATIVE_INFO MySQLNatives[] = 
    // ...
    {"cache_get_row_int",		Natives::getInstance()->n_cache_get_row_int},
    // ...
    {NULL, NULL}
I also ran a quick speedtest, comparing these 2 codes:
pawn Code:
goldpot_MaxID = cache_get_row_int(0, 0);
pawn Code:
cache_get_row(0, 0, str), goldpot_MaxID = strval(str);
It appears that the cache_get_row_int is 1,5 times faster than first using cache_get_row and then strval.

This function very much pleases me as it makes my job a lot easier, so huh, thought I'd share. Cannot share a working compiled version though since my version of the plugin is too heavily modified (and possibly a bit bugged in other areas).
AndreT is offline   Reply With Quote