Changes to mysql plugin
#1

Hi,

I'm in the process of upgrading my old game mode to use the latest version of the BlueG MySQL plugin and I am looking for some advise on converting the 'mysql_function_query' and cache functions.

Existing code:

Код:
mysql_function_query(mysql, "SELECT * FROM server_vehicles", true, "mysql_loadServerVehicles", "i", 1);
Код:
PUBLIC:mysql_loadServerVehicles(num) {
	print("mysql_loadServerVehicles");
    new svCars, fields;
    cache_get_data(svCars, fields);

	new rowstring[20];
	if(svCars > 0) {
		for (new svCar=0;svCar<svCars;svCar++){
			new temp_faction, vModel, Float:vPos[4], vColour1, vColour2, plateSet[30], plate[10];

			cache_get_field_content(svCar,  "vModel",rowstring, mysql);			vModel = int:strval(rowstring);
			cache_get_field_content(svCar,  "vPosX",rowstring, mysql);			vPos[0] = floatstr(rowstring);
			cache_get_field_content(svCar,  "vPosY",rowstring, mysql);			vPos[1] = floatstr(rowstring);
			cache_get_field_content(svCar,  "vPosZ",rowstring, mysql);			vPos[2] = floatstr(rowstring);
			cache_get_field_content(svCar,  "vPosR",rowstring, mysql);			vPos[3] = floatstr(rowstring);
			cache_get_field_content(svCar,  "vColour1",rowstring, mysql);		vColour1 = int:strval(rowstring);
			cache_get_field_content(svCar,  "vColour2",rowstring, mysql);		vColour2 = int:strval(rowstring);
			cache_get_field_content(svCar,  "vFaction",rowstring, mysql);		temp_faction = int:strval(rowstring);
			
			// Vehicle Creation
		}
	}
	return 1;
}
So the first bits going ok
Код:
mysql_tquery(mysql, "SELECT * FROM server_vehicles", "mysql_loadServerVehicles", "i", 1);
But the cache functions have now changed and im hoping someone may have some example code using the new cache functions, any help is appreciated.

The cache_get_value_name function looks a good start but I can't seem to find example code for looping through the results row by row.


Grim
Reply
#2

You're on a good path. cache_get_data can be replaced with cache_num_rows (which only returns number of rows). Check out https://github.com/pBlueG/SA-MP-MySQ...a_mysql.inc.in for all the latest functions
You don't need string to int/float conversion anymore:
pawn Код:
cache_get_field_content(svCar,  "vPosX",rowstring, mysql);          vPos[0] = floatstr(rowstring);
// turns into
cache_get_value_name_float(svCar, "vPosX", vPos[0], mysql);
Reply
#3

Ah ok, thanks was sure it was something simple I was missing haha
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)