Mysql R7 cache_get_row Problem
#1

Hi, i am trying to make auto-login in my registration script, but i am getting unexpected error:

Код:
public OnPlayerConnect(playerid)
{
	new playerName[MAX_PLAYER_NAME],EscPName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, playerName, sizeof(playerName));
	mysql_real_escape_string(playerName,EscPName,connection);
	ResetPVars(playerid);//connection
        format(szQueryInput, sizeof(szQueryInput), "SELECT `Ip` FROM `Players` WHERE `PlayerName` = '%s' LIMIT 0,1",EscPName);
        mysql_function_query(connection, szQueryInput, true, "CheckPlayerAccount", "i", playerid);
	return 1;
}

public CheckPlayerAccount(playerid, account[])
{
    new rows, fields;
    new ConnectedIP[16];
    GetPlayerIp(playerid, ConnectedIP, sizeof(ConnectedIP));
    cache_get_data(rows, fields, connection);
    
    if(rows)
	{
          cache_get_row(0, 3, PlayerVar[playerid][PIP], connection);
          printf("Connected IP is %s | Saved IP is %s!",ConnectedIP, PlayerVar[playerid][PIP]);
          if(strlen(PlayerVar[playerid][PIP]) != 0 && !strcmp(PlayerVar[playerid][PIP], ConnectedIP, true)) 
          {
            SendClientMessage(playerid,COLOR_RED,"IP match");
            ShowLoginDialog
          }
          else
          {
			ShowLoginDialog// This is my defined Login dialog
			SendClientMessage(playerid,COLOR_RED,"IP differs");
          }
	}
	else
	{
	   	  ShowRegisterDialog // This is my defined Register dialog
	}
	return 1;
}
So when i try to log in into my server using this:
Код:
format(szQueryInput, sizeof(szQueryInput), "SELECT `Ip` FROM `Players` WHERE `PlayerName` = '%s' LIMIT 0,1",EscPName);
I get don't send message which is caused by samp-server.exe.

Then i tried this option:
Код:
format(szQueryInput, sizeof(szQueryInput), "SELECT * FROM `Players` WHERE `PlayerName` = '%s' LIMIT 0,1",EscPName);
And script seems to work fine.

Also i tested this configuration:
Код:
format(szQueryInput, sizeof(szQueryInput), "SELECT * FROM `Players` WHERE `PlayerName` = '%s' LIMIT 0,1",EscPName);
and replaced this line:
Код:
cache_get_row(0, 3, PlayerVar[playerid][PIP], connection);
with this one:
Код:
cache_get_field_content(0, "Ip",PlayerVar[playerid][PIP], connection);
script works also fine.

Configuration of
Код:
format(szQueryInput, sizeof(szQueryInput), "SELECT `Ip` FROM `Players` WHERE `PlayerName` = '%s' LIMIT 0,1",EscPName);
and
Код:
cache_get_field_content(0, "Ip",PlayerVar[playerid][PIP], connection);
also works fine.

So my question is why i am getting don't send error in my script when i use this lines:
Код:
format(szQueryInput, sizeof(szQueryInput), "SELECT `Ip` FROM `Players` WHERE `PlayerName` = '%s' LIMIT 0,1",EscPName);
Код:
cache_get_row(0, 3, PlayerVar[playerid][PIP], connection);
I am using Windows Xp Sp3 operating system.

Also i add mysql configuration:
Код:
mysql_function_query(connection, "CREATE TABLE IF NOT EXISTS `Players` ( \
		`Id` int(11) NOT NULL AUTO_INCREMENT, \
		`PlayerName` varchar(24) NOT NULL, \
		`Password` varchar(64) NOT NULL, \
		`Ip` varchar(30) NOT NULL, \
		`Kills` int(5) NOT NULL, \
		`Deaths` int(5) NOT NULL, \
		`Money` int(5) NOT NULL, \
		`Level` int(5) NOT NULL, \
		`Minutes` int(5) NOT NULL, \
		`Hours` int(5) NOT NULL, \
		`Visits` int(8) NOT NULL, \
		PRIMARY KEY (`id`) \
	)", false, "", "");
Reply
#2

Код:
cache_get_row(0, 3, PlayerVar[playerid][PIP], connection);
Should be changed to
Код:
cache_get_row(0, 0, PlayerVar[playerid][PIP], connection);
You are only SELECTING one field in the query, which is IP.
Reply
#3

Thanks for fast reply.
Problem solved.

I didn't thought that i must use 0 instead 3 when selecting only one field from row.
Reply
#4

Код:
SELECT ip, name, score FROM ..
For example, ip = row 0, name = row 1, score = row 2

Only if you are using the * operator, you have to use the actual row in the table structure.

Glad I could help
Reply
#5

Guys. You both seem to have advanced knowledge of the R7 MySQL caching, could you possibly help me with my caching question please, it would be much appreciated I'll +rep

https://sampforum.blast.hk/showthread.php?tid=410021
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)