mysql problem
#1

Why it gives Server Unknow command? There is no warning or any print error from mysql. There might be some mistake from the code below. Please let me know. thank you!

Код:
COMMAND:top(playerid, params[])
{
	new
		Query[160],
	    count = 10,
	    result[2][32],
 		stringt[(24 + 10) * 10];

	mysql_format(gSQL, Query, "SELECT `Score`, `PlayerName` FROM `"#MYSQL_TABLE"` ORDER BY `Score` ASC LIMIT 10");
	mysql_function_query(gSQL, Query, true, "LoadPlayer", "d", playerid);
	
	if (mysql_num_rows() < 1) return 0;
	
	while (mysql_retrieve_row() && count > 0)
	{
		mysql_fetch_field_row(result[0], "Score");
		mysql_fetch_field_row(result[1], "PlayerName");

		format(stringt, sizeof(stringt), "%s%d. %s: %d\n", stringt, count--, result[1],strval(result[0]));
	}
	ShowPlayerDialog(playerid, 1223, DIALOG_STYLE_MSGBOX, "Top 10", stringt, "Close", "");
	return 1;
}
Reply
#2

Debug the code to a few pieces, to help you find out which number didn't get called. (take a look in the server console)
pawn Код:
COMMAND:top(playerid, params[])
{
    new
        Query[160],
        count = 10,
        result[2][32],
        stringt[(24 + 10) * 10];

    print("1");

    mysql_format(gSQL, Query, "SELECT `Score`, `PlayerName` FROM `"#MYSQL_TABLE"` ORDER BY `Score` ASC LIMIT 10");
    mysql_function_query(gSQL, Query, true, "LoadPlayer", "d", playerid);
   
    print("2");

    if (mysql_num_rows() < 1) return 0;

    print("3");
    while (mysql_retrieve_row() && count > 0)
    {
        mysql_fetch_field_row(result[0], "Score");
        mysql_fetch_field_row(result[1], "PlayerName");

        print("4");

        format(stringt, sizeof(stringt), "%s%d. %s: %d\n", stringt, count--, result[1],strval(result[0]));
    }
    ShowPlayerDialog(playerid, 1223, DIALOG_STYLE_MSGBOX, "Top 10", stringt, "Close", "");
    print("5");
    return 1;
}
Reply
#3

Quote:
Originally Posted by Loot
Посмотреть сообщение
Debug the code to a few pieces, to help you find out which number didn't get called. (take a look in the server console)
pawn Код:
COMMAND:top(playerid, params[])
{
    new
        Query[160],
        count = 10,
        result[2][32],
        stringt[(24 + 10) * 10];

    print("1");

    mysql_format(gSQL, Query, "SELECT `Score`, `PlayerName` FROM `"#MYSQL_TABLE"` ORDER BY `Score` ASC LIMIT 10");
    mysql_function_query(gSQL, Query, true, "LoadPlayer", "d", playerid);
   
    print("2");

    if (mysql_num_rows() < 1) return 0;

    print("3");
    while (mysql_retrieve_row() && count > 0)
    {
        mysql_fetch_field_row(result[0], "Score");
        mysql_fetch_field_row(result[1], "PlayerName");

        print("4");

        format(stringt, sizeof(stringt), "%s%d. %s: %d\n", stringt, count--, result[1],strval(result[0]));
    }
    ShowPlayerDialog(playerid, 1223, DIALOG_STYLE_MSGBOX, "Top 10", stringt, "Close", "");
    print("5");
    return 1;
}
Hope someone know how to fix this.


Код:
[17:38:10] [join] test has joined the server (0:127.0.0.1)
[17:38:24] 1
[17:38:26] 2
[17:38:26] 1
[17:38:26] 2
[17:38:28] [part] test has left the server (0:1)
Is that mean there are warnings from 1 and 2? coz I tried to use /top 2 times.
Reply
#4

Looks like the query returned false as far as I can tell, since it stopped before number 3.
Is MYSQL_TABLE defined? I've never seen someone using '#MYSQL_TABLE' with a '#' before, but I might be wrong.
Reply
#5

Quote:
Originally Posted by Loot
Посмотреть сообщение
Looks like the query returned false as far as I can tell, since it stopped before number 3.
Is MYSQL_TABLE defined? I've never seen someone using '#MYSQL_TABLE' with a '#' before, but I might be wrong.
Код:
#define MYSQL_TABLE       		"account"          //The table name where to save
Anyway im using MellAdmin this requires latest mysql R7
Reply
#6

I'm not that familiar with R7, sorry, but try:
pawn Код:
mysql_format(gSQL, Query, "SELECT `Score`, `PlayerName` FROM `account` ORDER BY `Score` ASC LIMIT 10");
Reply
#7

Quote:
Originally Posted by Loot
Посмотреть сообщение
I'm not that familiar with R7, sorry, but try:
pawn Код:
mysql_format(gSQL, Query, "SELECT `Score`, `PlayerName` FROM `account` ORDER BY `Score` ASC LIMIT 10");
Same thing debug 1 and 2.

Also I tried to do this

Код:
mysql_format(gSQL, Query, "SELECT `Score`, `PlayerName` FROM `account` ORDER BY `Score` ASC LIMIT 10", GetName(playerid));
and
Код:
format(Query, sizeof(Query), "SELECT `Score`, `PlayerName` FROM `"#MYSQL_TABLE"` ORDER BY `Score` ASC LIMIT 10", GetName(playerid));
and I don't know whats the difference. Well anyway thanks brother.
Reply
#8

That's very odd, make sure that the table names above exist, and double check the SQL logs, there must be an error message..
Reply
#9

Ok 1, what is this line for:
pawn Код:
mysql_function_query(gSQL, Query, true, "LoadPlayer", "d", playerid);
?
2. You didn't store the result
3. Check your mysql_debug.txt file to see what's wrong.
Reply
#10

Quote:
Originally Posted by Loot
Посмотреть сообщение
That's very odd, make sure that the table names above exist, and double check the SQL logs, there must be an error message..
I tried double check each and there was nothing wrong no warning or error.

There is something wrong with this line

Код:
	mysql_format(gSQL, Query, "SELECT `Score`, `PlayerName` FROM `"#MYSQL_TABLE"` ORDER BY `Score` ASC LIMIT 10");
    mysql_function_query(gSQL, Query, true, "LoadPlayer", "d", playerid);
    mysql_store_result();
    
    print("2");
	if (mysql_num_rows() < 1) return 0;
But wheereee

Edit:

Whole code for top:

Код:
COMMAND:top(playerid, params[])
{
	new
	    count = 10,
	    result[2][32],
	    string[(24 + 10) * 10],
	    Query[128];

    print("1");
    
	mysql_format(gSQL, Query, "SELECT `Score`, `PlayerName` FROM `"#MYSQL_TABLE"` ORDER BY `Score` ASC LIMIT 10");
    mysql_function_query(gSQL, Query, true, "LoadPlayer", "d", playerid);
    mysql_store_result();
    
    print("2");
	if (mysql_num_rows() < 1) return 0;
	
	print("3");
	while (mysql_retrieve_row() && count > 0)
	{
    	mysql_fetch_field_row(result[0], "Score");
    	mysql_fetch_field_row(result[1], "PlayerName");
    	print("4");
    	format(string, sizeof(string), "%s%d. %s: %d\n", string, count--, result[1], strval(result[0]));
	}
 	mysql_free_result();
	ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Top 10", string, "Close", "");
	print("5");
	return 1;
}
OMG What I have done! Hmm. there is something wrong?

Quote:

[19:27:35] >> mysql_connect(127.0.0.1, root, account, ******) on port 3306
[19:27:35] CMySQLHandler::CMySQLHandler() - constructor called.
[19:27:35] CMySQLHandler::CMySQLHandler() - Connecting to "127.0.0.1" | DB: "account" | Username: "root"
[19:27:35] CMySQLHandler::Connect() - Connection was successful.
[19:27:35] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.
[19:27:35] >> mysql_ping( Connection handle: 1 )
[19:27:35] CMySQLHandler::Ping() - Connection is still alive.
[19:27:55] >> mysql_ping( Connection handle: 1 )
[19:27:55] CMySQLHandler::Ping() - Connection is still alive.
[19:27:55] >> mysql_query_callback( Connection handle: 1 )
[19:27:55] Passing query SELECT * FROM `account` WHERE `PlayerName` = 'test' | siii
[19:27:55] ProcessQueryThread(OnQueryFinish) - Query was successful. (SELECT * FROM `account` WHERE `PlayerName` = 'test')
[19:27:55] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[19:27:55] OnQueryFinish(siii) - Threaded function called.
[19:27:55] >> mysql_store_result( Connection handle: 1 )
[19:27:55] CMySQLHandler::StoreResult() - Result was stored.
[19:27:55] >> mysql_num_rows( Connection handle: 1 )
[19:27:55] CMySQLHandler::NumRows() - Returned 1 row(s)
[19:27:55] >> mysql_ping( Connection handle: 1 )
[19:27:55] CMySQLHandler::Ping() - Connection is still alive.
[19:27:55] >> mysql_query_callback( Connection handle: 1 )
[19:27:55] >> mysql_free_result( Connection handle: 1 )
[19:27:55] CMySQLHandler::FreeResult() - Result was successfully free'd.
[19:27:55] Passing query SELECT `Status` FROM `account` WHERE `PlayerName` = 'test' AND `Status` = 2 | siii
[19:27:55] ProcessQueryThread(OnQueryFinish) - Query was successful. (SELECT `Status` FROM `account` WHERE `PlayerName` = 'test' AND `Status` = 2)
[19:27:55] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[19:27:55] OnQueryFinish(siii) - Threaded function called.
[19:27:55] >> mysql_store_result( Connection handle: 1 )
[19:27:55] CMySQLHandler::StoreResult() - Result was stored.
[19:27:55] >> mysql_num_rows( Connection handle: 1 )
[19:27:55] CMySQLHandler::NumRows() - Returned 0 row(s)
[19:27:55] >> mysql_ping( Connection handle: 1 )
[19:27:55] CMySQLHandler::Ping() - Connection is still alive.
[19:27:55] >> mysql_query_callback( Connection handle: 1 )
[19:27:55] >> mysql_free_result( Connection handle: 1 )
[19:27:55] CMySQLHandler::FreeResult() - Result was successfully free'd.
[19:27:55] Passing query SELECT `LastIP` FROM `account` WHERE `PlayerName` = 'test' AND `LastIP` = '127.0.0.1' | siii
[19:27:55] ProcessQueryThread(OnQueryFinish) - Query was successful. (SELECT `LastIP` FROM `account` WHERE `PlayerName` = 'test' AND `LastIP` = '127.0.0.1')
[19:27:55] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[19:27:55] OnQueryFinish(siii) - Threaded function called.
[19:27:55] >> mysql_store_result( Connection handle: 1 )
[19:27:55] CMySQLHandler::StoreResult() - Result was stored.
[19:27:55] >> mysql_num_rows( Connection handle: 1 )
[19:27:55] CMySQLHandler::NumRows() - Returned 1 row(s)
[19:27:55] >> mysql_ping( Connection handle: 1 )
[19:27:55] CMySQLHandler::Ping() - Connection is still alive.
[19:27:55] >> mysql_query_callback( Connection handle: 1 )
[19:27:55] >> mysql_ping( Connection handle: 1 )
[19:27:55] CMySQLHandler::Ping() - Connection is still alive.
[19:27:55] >> mysql_query_callback( Connection handle: 1 )
[19:27:55] >> mysql_free_result( Connection handle: 1 )
[19:27:55] CMySQLHandler::FreeResult() - Result was successfully free'd.
[19:27:55] Passing query SELECT `XPos`,`YPos`,`ZPos`,`AdminLevel`,`VIPLevel`,`Want edLevel`,`Kills`,`Deaths`,`Money`,`Score`,`Health` ,`Armour`,`Hours`,`Minutes`,`Seconds`,`KickCount`, `LastSkin`,`SpawnCount`,`ReportCount`,`Warnings`,` FailLogin`,`RconAttempt`,`RegDate` FROM `account` WHERE `PlayerName` = 'test' | siii
[19:27:55] ProcessQueryThread(OnQueryFinish) - Query was successful. (SELECT `XPos`,`YPos`,`ZPos`,`AdminLevel`,`VIPLevel`,`Want edLevel`,`Kills`,`Deaths`,`Money`,`Score`,`Health` ,`Armour`,`Hours`,`Minutes`,`Seconds`,`KickCount`, `LastSkin`,`SpawnCount`,`ReportCount`,`Warnings`,` FailLogin`,`RconAttempt`,`RegDate` FROM `account` WHERE `PlayerName` = 'test')
[19:27:55] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[19:27:55] OnQueryFinish(siii) - Threaded function called.
[19:27:55] >> mysql_store_result( Connection handle: 1 )
[19:27:55] CMySQLHandler::StoreResult() - Result was stored.
[19:27:55] >> mysql_num_rows( Connection handle: 1 )
[19:27:55] CMySQLHandler::NumRows() - Returned 1 row(s)
[19:27:55] >> mysql_fetch_row_format( Connection handle: 1 )
[19:27:55] CMySQLHandler::FetchRow() - Return: -2571.57|328.51|10.56|6|0|0|0|9|69800|0|100|0|1|49| 1|0|108|52|0|0|0|1|11/11/2013
[19:27:55] >> mysql_free_result( Connection handle: 1 )
[19:27:55] CMySQLHandler::FreeResult() - Result was successfully free'd.
[19:27:55] Passing query UPDATE `account` SET `LastIP` = '127.0.0.1', `Status` = 1 WHERE `PlayerName` = 'test' | siii
[19:27:55] ProcessQueryThread(OnQueryFinish) - Query was successful. (UPDATE `account` SET `LastIP` = '127.0.0.1', `Status` = 1 WHERE `PlayerName` = 'test')
[19:27:55] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[19:27:55] OnQueryFinish(siii) - Threaded function called.
[19:28:08] >> mysql_format( Connection handle: 1 )
[19:28:08] >> mysql_query_callback( Connection handle: 1 )
[19:28:08] >> mysql_store_result( Connection handle: 1 )
[19:28:08] CMySQLHandler::StoreResult() - No data to store.
[19:28:08] Passing query SELECT `Score`, `PlayerName` FROM `account` ORDER BY `Score` ASC LIMIT 10 | d
[19:28:08] ProcessQueryThread(LoadPlayer) - Query was successful. (SELECT `Score`, `PlayerName` FROM `account` ORDER BY `Score` ASC LIMIT 10)
[19:28:08] ProcessQueryThread(LoadPlayer) - Data caching enabled.
[19:28:08] CMySQLHandler::StoreResult() - Result was stored.
[19:28:08] CMySQLHandler::FreeResult() - Result was successfully free'd.
[19:28:08] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[19:28:08] >> mysql_num_rows( Connection handle: 1 )
[19:28:08] CMySQLHandler::NumRows() - You cannot call this function now. (Reason: Dead Connection)
[19:28:09] >> mysql_ping( Connection handle: 1 )
[19:28:09] CMySQLHandler::Ping() - Connection is still alive.
[19:28:09] >> mysql_query_callback( Connection handle: 1 )
[19:28:09] >> mysql_ping( Connection handle: 1 )
[19:28:09] CMySQLHandler::Ping() - Connection is still alive.
[19:28:09] >> mysql_query_callback( Connection handle: 1 )
[19:28:09] Passing query UPDATE `account` SET `XPos` = -2571.57, `YPos` = 328.51, `ZPos` = 10.56, `AdminLevel` = 6, `VIPLevel` = 0, `WantedLevel` = 0, `Kills` = 0, `Deaths` = 9, `Money` = 69800, `Score` = 0, `Health` = 100.00, `Armour` = 0.00, `Hours` = 1, `Minutes` = 49, `Seconds` = 15, `LastSkin` = 108, `KickCount` = 0, `SpawnCount` = 53, `ReportCount` = 0, `Warnings` = 0, `FailLogin` = 0, `RconAttempt` = 1 WHERE `PlayerName` = 'test' | siii
[19:28:09] ProcessQueryThread(OnQueryFinish) - Query was successful. (UPDATE `account` SET `XPos` = -2571.57, `YPos` = 328.51, `ZPos` = 10.56, `AdminLevel` = 6, `VIPLevel` = 0, `WantedLevel` = 0, `Kills` = 0, `Deaths` = 9, `Money` = 69800, `Score` = 0, `Health` = 100.00, `Armour` = 0.00, `Hours` = 1, `Minutes` = 49, `Seconds` = 15, `LastSkin` = 108, `KickCount` = 0, `SpawnCount` = 53, `ReportCount` = 0, `Warnings` = 0, `FailLogin` = 0, `RconAttempt` = 1 WHERE `PlayerName` = 'test')
[19:28:09] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[19:28:09] OnQueryFinish(siii) - Threaded function called.
[19:28:09] Passing query UPDATE `account` SET `LastSkin` = 108, `Status` = 0 WHERE `PlayerName` = 'test' | siii
[19:28:09] ProcessQueryThread(OnQueryFinish) - Query was successful. (UPDATE `account` SET `LastSkin` = 108, `Status` = 0 WHERE `PlayerName` = 'test')
[19:28:09] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[19:28:09] OnQueryFinish(siii) - Threaded function called.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)