SA-MP Forums Archive
retrieving data MySQL R39 - 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: retrieving data MySQL R39 (/showthread.php?tid=655952)



retrieving data MySQL R39 - div - 03.07.2018

Hello, I'm making a house system.. the house is made fine, data is also stored in MySQL..


But when the server restarts, it isn't getting the data from MySQL(House checkpoint gets destroyed, and isn't being retrieved from MySQL)



Here's my code under OnGameModeInit
Код:
for(new i = 0; i < MAX_HOUSES; i++)
	    {
	 	hInfo[i][HouseEX] = cache_get_field_content_float(0, "HouseEX");
 		hInfo[i][HouseEY] = cache_get_field_content_float(0, "HouseEY");
		hInfo[i][HouseEZ] = cache_get_field_content_float(0, "HouseEZ");
		cache_get_field_content_int(0, "HouseID", hInfo[i][HouseID]);
		hInfo[i][HouseCP] = CreateDynamicCP(hInfo[i][HouseEX], hInfo[i][HouseEZ], hInfo[i][HouseEZ], 1.5, .worldid = 0, .interiorid = 0, .streamdistance = 20.0);
		}
Completely unsure if it should work or not, but someone told me it would work fine..


Re: retrieving data MySQL R39 - Calisthenics - 03.07.2018

1) First parameter in cache_get_field_content* functions is rowid. You only retrieve from first row:
Код:
cache_get_field_content_float(0,
2) Wrong loop. It should be "i < rows" where rows are retrieved with cache_get_row_count/cache_num_rows before. Otherwise you will receive "no active cache" error in mysql logs.
3) In OnGameModeInit? If you do not execute a query before or even use mysql_tquery/mysql_pquery (without a callback), you will receive "no active cache" error again. If mysql_query was used, it is bad practice- always use threaded query.
4) Check if there are more rows than the size of hInfo array otherwise run time error 4.


Re: retrieving data MySQL R39 - div - 03.07.2018

What should I do now?


Re: retrieving data MySQL R39 - Calisthenics - 03.07.2018

Quote:
Originally Posted by div
Посмотреть сообщение
What should I do now?
Fix the code? I pointed out 4 mistakes, you do the rest.


Re: retrieving data MySQL R39 - div - 03.07.2018

How can i retrieve with any other way btw?


Re: retrieving data MySQL R39 - CodeStyle175 - 03.07.2018

well this loading code doesnt evne work do even understand what are you doing?
how can use max_houses for loading houses?
and when you dont understand nothing then you should build something simplier


Re: retrieving data MySQL R39 - div - 03.07.2018

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
well this loading code doesnt evne work do even understand what are you doing?
how can use max_houses for loading houses?
Fixed that.


EDIT: Problem isn't fixed yet..


Re: retrieving data MySQL R39 - div - 03.07.2018

How about this?
Код:
forward LoadHouses();
public LoadHouses()
{
    	new rows = cache_get_row_count();
    	for(new i = 0; i < rows; i++)
	    {
	    
	 	hInfo[i][HouseEX] = cache_get_field_content_float(0, "HouseEX");
 		hInfo[i][HouseEY] = cache_get_field_content_float(0, "HouseEY");
		hInfo[i][HouseEZ] = cache_get_field_content_float(0, "HouseEZ");
		cache_get_field_content_int(0, "HouseID", hInfo[i][HouseID]);
		hInfo[i][HouseCP] = CreateDynamicCP(hInfo[i][HouseEX], hInfo[i][HouseEZ], hInfo[i][HouseEZ], 1.5, .worldid = 0, .interiorid = 0, .streamdistance = 20.0);
		}

}

Код:
mysql_tquery(dbHandle, "SELECT * FROM `houses`", "LoadHouses", "");



Re: retrieving data MySQL R39 - div - 03.07.2018

help please


Re: retrieving data MySQL R39 - Calisthenics - 03.07.2018

Read #1 from the list again. rowid = i (iteration variable) not 0.