My console stop right after mysql_query(query)
#1

Hey guys, this is my first post here, and i have a problem with my house system.
I made it by myself, and when I try to load the houses, in OnGameModeInit, my console stop. I tried to figure out what my problem is by marking each step with a print in console, and found out that it stop right after mysql_query(query).

Here is my code, and the server_log, in diffrent forms (I tried many structures, and all of them stopped at the same point):

#1

Код:
stock MySQL_LoadHouse()
{
print("0");
new query24[500],savingstring[400];
print("0.1");
for(new hid=1;hid<=MAX_HOUSES;hid++)
	{
	print("0.2");
	format(query24,sizeof(query24),"SELECT id, owner, level, text, renters, rentprice, rentable, price, upgrade, locked, enterX, enterY, enterZ, exitX, exitY, exitZ, interior, virtual FROM `houses` WHERE id = %d LIMIT 2",hid);
	print("0.3");
	mysql_query(query24);
 	print("1");
	mysql_store_result();
	print("2");
	while(mysql_fetch_row(query24,"|"))
		{
		print("3");
		mysql_fetch_field("id",savingstring);
		HouseInfo[hid][hId]=strval(savingstring);
		print("4");
		mysql_fetch_field("owner",savingstring);
		strins(HouseInfo[hid][hOwner],savingstring,1);
		print("5");
		mysql_fetch_field("level",savingstring);
		HouseInfo[hid][hLevel]=strval(savingstring);
		print("6");
		mysql_fetch_field("text",savingstring);
		strins(HouseInfo[hid][hText],savingstring,1);
		print("7");
		mysql_fetch_field("renters",savingstring);
		HouseInfo[hid][hRenters]=strval(savingstring);
		print("8");
		mysql_fetch_field("rentprice",savingstring);
		HouseInfo[hid][hRentprice]=strval(savingstring);
		print("9");
		mysql_fetch_field("rentable",savingstring);
		HouseInfo[hid][hRentable]=strval(savingstring);
		print("10");
		mysql_fetch_field("price",savingstring);
		HouseInfo[hid][hPrice]=strval(savingstring);
		print("11");
		mysql_fetch_field("upgrade",savingstring);
		HouseInfo[hid][hUpgrade]=strval(savingstring);
		print("12");
		mysql_fetch_field("locked",savingstring);
		HouseInfo[hid][hLocked]=strval(savingstring);
		print("13");
		mysql_fetch_field("enterX",savingstring);
		HouseInfo[hid][hEnterX]=strval(savingstring);
		print("14");
		mysql_fetch_field("enterY",savingstring);
		HouseInfo[hid][hEnterY]=strval(savingstring);
		print("15");
		mysql_fetch_field("enterZ",savingstring);
		HouseInfo[hid][hEnterZ]=strval(savingstring);
		print("16");
		mysql_fetch_field("exitX",savingstring);
		HouseInfo[hid][hExitX]=strval(savingstring);
		print("17");
		mysql_fetch_field("exitY",savingstring);
		HouseInfo[hid][hExitY]=strval(savingstring);
		print("18");
		mysql_fetch_field("exitZ",savingstring);
		HouseInfo[hid][hExitZ]=strval(savingstring);
		print("19");
		mysql_fetch_field("interior",savingstring);
		HouseInfo[hid][hInterior]=strval(savingstring);
		print("20");
		mysql_fetch_field("virtual",savingstring);
		HouseInfo[hid][hVirtual]=strval(savingstring);
		print("21");
		}
	print("22");
	mysql_free_result();
	print("23");
	Create3DTextLabel(HouseInfo[hid][hText],COL_WHITE,HouseInfo[hid][hEnterX],HouseInfo[hid][hEnterY],HouseInfo[hid][hEnterZ],30.0,0,1);
	print("24");
	}
}
And the server log:


----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3z, ©2005-2014 SA-MP Team

[19:14:27]
[19:14:27] Server Plugins
[19:14:27] --------------
[19:14:27] Loading plugin: mysql
[19:14:27] SA:MP MySQL Plugin v2.1.1 Loaded.
[19:14:27] Loaded.
[19:14:27] Loading plugin: sscanf
[19:14:27] [MySQL] Thread running. Threadsafe: Yes.
[19:14:27]

[19:14:27] ===============================

[19:14:27] sscanf plugin loaded.

[19:14:27] Version: 2.8.1

[19:14:27] © 2012 Alex "******" Cole

[19:14:27] ===============================

[19:14:27] Loaded.
[19:14:27] Loading plugin: streamer
[19:14:27]

*** Streamer Plugin v2.6.1 by Incognito loaded ***

[19:14:27] Loaded.
[19:14:27] Loaded 3 plugins.

[19:14:27]
[19:14:27] Ban list
[19:14:27] --------
[19:14:27] Loaded: samp.ban
[19:14:27]
[19:14:27]
[19:14:27] Filterscripts
[19:14:27] ---------------
[19:14:27] Loading filterscript 'gl_realtime.amx'...
[19:14:27] Loaded 1 filterscripts.

[19:14:27] Houses not loaded yet.
[19:14:27] 0
[19:14:27] 0.1
[19:14:27] 0.2
[19:14:27] 0.3

#2

Код:
stock MySQL_LoadHouse()
{
new query[400];
for(new hid=1; hid <= MAX_HOUSES; hid++)
{
	print("0");
	format(query, sizeof(query), "SELECT * FROM `houses` WHERE `id` = %d", hid);
    print("1");
	mysql_query(query);
	print("2");
}
}
And the server log:


----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3z, ©2005-2014 SA-MP Team

[19:16:03]
[19:16:03] Server Plugins
[19:16:03] --------------
[19:16:03] Loading plugin: mysql
[19:16:03] SA:MP MySQL Plugin v2.1.1 Loaded.
[19:16:03] Loaded.
[19:16:03] Loading plugin: sscanf
[19:16:03] [MySQL] Thread running. Threadsafe: Yes.
[19:16:03]

[19:16:03] ===============================

[19:16:03] sscanf plugin loaded.

[19:16:03] Version: 2.8.1

[19:16:03] © 2012 Alex "******" Cole

[19:16:03] ===============================

[19:16:03] Loaded.
[19:16:03] Loading plugin: streamer
[19:16:03]

*** Streamer Plugin v2.6.1 by Incognito loaded ***

[19:16:03] Loaded.
[19:16:03] Loaded 3 plugins.

[19:16:03]
[19:16:03] Ban list
[19:16:03] --------
[19:16:03] Loaded: samp.ban
[19:16:03]
[19:16:03]
[19:16:03] Filterscripts
[19:16:03] ---------------
[19:16:03] Loading filterscript 'gl_realtime.amx'...
[19:16:03] Loaded 1 filterscripts.

[19:16:03] Houses not loaded yet.
[19:16:03] 0
[19:16:03] 1

And, OnGameModeInit:

Код:
        print("Houses not loaded yet.");
	MySQL_LoadHouse();
	print("Houses loaded");
Please help me, I'm stuck on this for over 1 week. This is the latest phase I could reach. I don't know what is wrong there.
Reply
#2

pawn Код:
format(query24,sizeof(query24),"SELECT id, owner, level, text, renters, rentprice, rentable, price, upgrade, locked, enterX, enterY, enterZ, exitX, exitY, exitZ, interior, virtual FROM `houses` WHERE id = %d LIMIT 2",hid);
put a line under that one:
pawn Код:
printf( "%s", query24 );
re-run the console and post the prints here, so we can see what the actual query is, that's being sent.
Reply
#3

This is what I got:

Код:
...
[19:36:33] Filterscripts
[19:36:33] ---------------
[19:36:33]   Loading filterscript 'gl_realtime.amx'...
[19:36:33]   Loaded 1 filterscripts.

[19:36:33] Houses not loaded yet.
[19:36:33] 0
[19:36:33] 0.1
[19:36:33] 0.2
[19:36:33] 0.3
[19:36:33] SELECT id, owner, level, text, renters, rentprice, rentable, price, upgrade, locked, enterX, enterY, enterZ, exitX, exitY, exitZ, interior, virtual FROM `houses` WHERE id = 1 LIMIT 2
P.S I tried also without LIMIT 1 or 2 or anything else.
Reply
#4

Bump. Any ideas?
Reply
#5

Bump. Still no idea about what's wrong. I would like some help.
Reply
#6

First of all, NEVER EVER run queries inside a loop. That's not how databases work! Also, install crashdetect
Reply
#7

Quote:
Originally Posted by Misiur
Посмотреть сообщение
First of all, NEVER EVER run queries inside a loop. That's not how databases work! Also, install crashdetect
And then, how am I supposed to load the houses when the server starts? I thought this is the single way to load all the houses from MySQL.
Reply
#8

Query is the heaviest thing your gamemode can do (big simplification, but whatever). The less queries fired, the better. With a single query you can fetch all results from multiple various tables (SQL is powerful!). So, instead using one query per house, run one query for all houses, and then map results to your array.

pawn Код:
stock MySQL_LoadHouse()
{
    new
        str[512]
    ;

    mysql_query("SELECT * FROM houses");
    mysql_store_result();
    while(mysql_fetch_row(str,"|")) {
        //Do something
    }
    mysql_free_result();
}
Also, unthreaded queries will pause your script execution, until the query is finished, that's why you should use threaded queries (available in most of MySQL plugins). Search around forum for threaded queries tutorial, or better yet, use ORM system from BlueG plugin.


Keep in mind, that database id shouldn't be your array index.
Reply
#9

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Query is the heaviest thing your gamemode can do (big simplification, but whatever). The less queries fired, the better. With a single query you can fetch all results from multiple various tables (SQL is powerful!). So, instead using one query per house, run one query for all houses, and then map results to your array.

pawn Код:
stock MySQL_LoadHouse()
{
    new
        str[512]
    ;

    mysql_query("SELECT * FROM houses");
    mysql_store_result();
    while(mysql_fetch_row(str,"|")) {
        //Do something
    }
    mysql_free_result();
}
Also, unthreaded queries will pause your script execution, until the query is finished, that's why you should use threaded queries (available in most of MySQL plugins). Search around forum for threaded queries tutorial, or better yet, use ORM system from BlueG plugin.


Keep in mind, that database id shouldn't be your array index.
And, in your example, how can I add a value to a certain house id? Because, when I add a value to a matrix, I have hid (house id) there. So the house with that id will receive that info.

I mean I am not sure about that query you've posted. Can you explain how to adapt that in my case?

Код:
mysql_fetch_field("id",savingstring);
HouseInfo[hid][hId]=strval(savingstring);
mysql_fetch_field("owner",savingstring);
strins(HouseInfo[hid][hOwner],savingstring,1);
mysql_fetch_field("level",savingstring);
HouseInfo[hid][hLevel]=strval(savingstring);
Anyway, thank you for your explanation till' now. I am not so experienced.
Reply
#10

I'm not familiar with that plugin, and I don't know which function moves the internal current result pointer. You can't use the database id's as array indexes, because they are very dynamic (well, that depends on implementation, but that's not important).

pawn Код:
new
    str[512]
;

mysql_query("SELECT * FROM houses");
mysql_store_result();
for(new hid = 0; hid != MAX_HOUSES && mysql_fetch_row(str, "|"); ++hid) {
    mysql_fetch_field("id", str);
    HouseInfo[hid][hId] = strval(str);
    //Further things
}
mysql_free_result();
Something like this. But, doesn't mysql_fetch_row return whole row at once? Why do you have to use mysql_fetch_field instead of splitting that one? I think there was some method using sscanf, but I can't remember where it was described now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)