MYSQL R39-3 - Invalid rows / Invalid Fields
#1

Hello, I am currently scripting a login system with MySQL R39 with Threading, and as it is my first attempt with anything with threading.. I am not currently sure on what to do however I am trying but I have found an issue with my script that I was hoping someone could help.

So the problem is.. it finds the rows and fields that are within the db however it doesn't seem to access it.
Код:
stock LoginPlayer(playerid, password[])
{
	mysql_format(1, query, sizeof(query), "SELECT * FROM master_data WHERE Username = '%e' AND Pass = '%e'", Username(playerid), password);
	mysql_query(1, query);
	cache_get_data(rows, fields);
	printf("There are currently %i rows and %i fields visable in the master_data db", rows, fields);
	if(cache_get_row_count() > 0)
 	{
		//format(query, sizeof(query), "UPDATE master_data SET LastIP = '%s' WHERE Username = '%s'", PlayerIP(playerid), Username(playerid));
		//mysql_query(query);
		cache_get_row(rows, 4, query);
		if(strfind(query, "")) return query = "Create Character";
		MasterData[playerid][Char0] = query;
		print("Char0 set");
		cache_get_row(rows, 5, query);
		if(strfind(query, "")) return query = "Create Character";
		MasterData[playerid][Char1] = query;
		print("Char1 set");
		cache_get_row(rows, 6, query);
		if(strfind(query, "")) return query = "Create Character";
		MasterData[playerid][Char2] = query;
		print("Char2 set");
		//format(msg, sizeof(msg), "Welcome back %s.\nYour stats have been loaded succesfully.\nThe last login for this account was from IP: %s", PlayerName(playerid), Player_Data[playerid][Last_IP]);
		format(str, sizeof(str), "%s\n%s\n%s\n \nAccount Settings", MasterData[playerid][Char0], MasterData[playerid][Char1], MasterData[playerid][Char2]);
		ShowPlayerDialog(playerid, DIALOG_CHARSELECT, DIALOG_STYLE_LIST, "Duck's Roleplay - Account", str, "Select", "Quit");
		print("Dialog should be shown here");
	}
	else
	{
	 	ShowPlayerDialog(playerid, DIALOG_RETRY, DIALOG_STYLE_PASSWORD, "Duck's Roleplay - Login", "Incorrect password!\nPlease enter your account password below:", "Login", "Quit");
	}
	return 1;
}
Here is the mysql_log.
Код:
[14:33:26] [DEBUG] mysql_connect - host: "---.-.-.-", user: "---", database: "---", password: "*---", port: ----, autoreconnect: true, pool_size: 2
[14:33:26] [DEBUG] CMySQLHandle::Create - creating new connection..
[14:33:26] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[14:33:26] [DEBUG] CMySQLHandle::Create - connection created (id: 1)
[14:33:26] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[14:33:26] [DEBUG] CMySQLConnection::Connect - connection was successful
[14:33:26] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[14:33:26] [DEBUG] mysql_errno - connection: 1
[14:33:26] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[14:33:26] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[14:33:26] [DEBUG] CMySQLConnection::Connect - connection was successful
[14:33:26] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[14:33:26] [DEBUG] CMySQLConnection::Connect - connection was successful
[14:33:26] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[14:33:26] [DEBUG] CMySQLConnection::Connect - connection was successful
[14:33:26] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[14:34:03] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT Count(ID) FROM master_data WHERE Username = '%e'"
[14:34:03] [DEBUG] mysql_query - connection: 1, query: "SELECT Count(ID) FROM master_data WHERE Username = 'Duck'", use_cache: true
[14:34:03] [DEBUG] CMySQLQuery::Execute - starting query execution
[14:34:03] [DEBUG] CMySQLQuery::Execute - query was successfully executed within 74.45 milliseconds
[14:34:03] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[14:34:03] [DEBUG] CMySQLHandle::SaveActiveResult - cache saved (id: 1)
[14:34:03] [DEBUG] cache_get_row_count - connection: 1
[14:34:10] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT * FROM master_data WHERE Username = '%e' AND Pass = '%e'"
[14:34:10] [DEBUG] mysql_query - connection: 1, query: "SELECT * FROM master_data WHERE Username = 'Duck' AND Pass = 'pa", use_cache: true
[14:34:10] [DEBUG] CMySQLQuery::Execute - starting query execution
[14:34:10] [DEBUG] CMySQLQuery::Execute - query was successfully executed within 1.49 milliseconds
[14:34:10] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[14:34:10] [DEBUG] CMySQLHandle::SaveActiveResult - cache saved (id: 2)
[14:34:10] [DEBUG] cache_get_data - connection: 1
[14:34:10] [DEBUG] cache_get_row_count - connection: 1
[14:34:10] [DEBUG] cache_get_row - row: 1, field_idx: 4, connection: 1, max_len: 128
[14:34:10] [WARNING] CMySQLResult::GetRowData - invalid row ('1') or field index ('4')
Help is much appreciated, thank you.
Reply
#2

Look this tutorial mate,it helped me to understand alot things.
https://sampforum.blast.hk/showthread.php?tid=485633
Reply
#3

Quote:
Originally Posted by MikE1990
Посмотреть сообщение
Look this tutorial mate,it helped me to understand alot things.
https://sampforum.blast.hk/showthread.php?tid=485633
A more in-depth tutorial edition on that tutorial was made by me, yesterday: https://sampforum.blast.hk/showthread.php?tid=574714. You might want to take a look at this too to give you a more in-depth explanation of MySQL logging and registering.
Reply
#4

I don't need to read a tutorial; I have already read plenty of them; I just need a fix for this small issue, Thank you anyway.
Reply
#5

Your log pretty much tells you what the problem is: you're trying to retrieve data from a field/row that is non-existent.

Quote:
Originally Posted by MySQL log
[14:34:10] [WARNING] CMySQLResult::GetRowData - invalid row ('1') or field index ('4')
And you do realise that you're not making use of any threaded queries in that snippet of code, right?
I believe you either haven't read the correct tutorials or you haven't read enough of them yet. Give these tutorials a look:

https://sampforum.blast.hk/showthread.php?tid=570635
https://sampforum.blast.hk/showthread.php?tid=485633 (More detailed: https://sampforum.blast.hk/showthread.php?tid=574714)
Reply
#6

Quote:
Originally Posted by Overhaul
Посмотреть сообщение
Your log pretty much tells you what the problem is: you're trying to retrieve data from a field/row that is non-existent.



And you do realise that you're not making use of any threaded queries in that snippet of code, right?
I believe you either haven't read the correct tutorials or you haven't read enough of them yet. Give these tutorials a look:

https://sampforum.blast.hk/showthread.php?tid=570635
https://sampforum.blast.hk/showthread.php?tid=485633 (More detailed: https://sampforum.blast.hk/showthread.php?tid=574714)
I know it cannot find the row/field however they're there and they are filled, so I can't see what the problem is..
and yes.. i know
Reply
#7

Quote:
Originally Posted by MotherDucker
Посмотреть сообщение
I know it cannot find the row/field however they're there and they are filled, so I can't see what the problem is..
and yes.. i know
Update your code with threaded queries. With help of the given tutorials in my previous reply, you should be able to get it right or are you waiting for me to give you the correct code with you only having to copy-paste it?
Reply
#8

Quote:
Originally Posted by Overhaul
Посмотреть сообщение
Update your code with threaded queries, with help of the given tutorials in my previous reply and you should be able to get it right or are you waiting for me to give you the correct code with you only having to copy-paste it?
No, absolutely not.. how will I learn by doing that? I am trying to figure out what is wrong with this code because I am stuck and I have been trying to figure that out for a while now.. I will read the topics you suggested however I already have a general understanding about threading, this is why I am making the system; to learn more about threading and improve my coding abilities.
Reply
#9

Quote:
Originally Posted by MotherDucker
Посмотреть сообщение
No, absolutely not.. how will I learn by doing that? I am trying to figure out what is wrong with this code because I am stuck and I have been trying to figure that out for a while now.. I will read the topics you suggested however I already have a general understanding about threading, this is why I am making the system; to learn more about threading and improve my coding abilities.
That's great.
I believe you can't use the 'rows' variable as the row ID's (as the first parameter for the cache_get_row functions). cache_get_data retrieves how many rows the database holds with the information provided - it is simply the result of a sum. Let me put an example to it: let us assume you have four accounts registered. The third account wants to login. The cache_get_data function tells us that there are 4 rows (one row per account) in that case the 'rows' variable will hold the value '4' and thus will retrieve the incorrect or even invalid information.

Instead, replace 'rows' with '0' and try again.

EDIT: I forgot to mention that we pick '0' as the row ID because it represents the first row found by the query.
Reply
#10

Alright.. I see what you're saying, but how would I achieve getting the row ID, setting it to a variable.. such as rowID and then replacing it so that it works.. i.e.

Код:
//Something here to get the rows id and put it into a variable
//then..
cache_get_row(rowID, 4, query);
Would there be another function involved? or would it just be something like..

Код:
mysql_format(1, query, sizeof(query), "SELECT ID FROM master_data WHERE Username = '%e' AND Pass = '%e'", Username(playerid), password);
new rowID = mysql_query(1, query);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)