Raised This Month: $13 Target: $400
 3% 

Problem MySQL T_LoadData


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PyKw
Junior Member
Join Date: Jan 2012
Old 08-20-2019 , 13:03   Problem MySQL T_LoadData
Reply With Quote #1

SOLVED!

Last edited by PyKw; 11-12-2019 at 05:17.
PyKw is offline
GetRektByNoob
Member
Join Date: Nov 2018
Old 08-20-2019 , 13:29   Re: Problem MySQL T_LoadData
Reply With Quote #2

can i ask why are you doing
Code:
results.FieldNameToNum("valoare", valoareCol);
and not
Code:
results.FieldNameToNum("valoare", 0);
since you are defining the int but not doing anything to it
also you posted half of the error, it should be something like this
Code:
L 08/20/2019 - 19:43:27: [SM] Exception reported: [Reason]
L 08/20/2019 - 19:43:27: [SM] Blaming: testNewDb.smx
L 08/20/2019 - 19:43:27: [SM] Call stack trace:
L 08/20/2019 - 19:43:27: [SM]   [0] DBResultSet.FieldNameToNum
L 08/20/2019 - 19:43:27: [SM]   [1] Line 77, testNewDb.sp::T_LoadData

Last edited by GetRektByNoob; 08-20-2019 at 13:30.
GetRektByNoob is offline
PyKw
Junior Member
Join Date: Jan 2012
Old 08-20-2019 , 13:55   Re: Problem MySQL T_LoadData
Reply With Quote #3

Quote:
Originally Posted by GetRektByNoob View Post
can i ask why are you doing
Code:
results.FieldNameToNum("valoare", valoareCol);
and not
Code:
results.FieldNameToNum("valoare", 0);
since you are defining the int but not doing anything to it
also you posted half of the error, it should be something like this
Code:
L 08/20/2019 - 19:43:27: [SM] Exception reported: [Reason]
L 08/20/2019 - 19:43:27: [SM] Blaming: testNewDb.smx
L 08/20/2019 - 19:43:27: [SM] Call stack trace:
L 08/20/2019 - 19:43:27: [SM]   [0] DBResultSet.FieldNameToNum
L 08/20/2019 - 19:43:27: [SM]   [1] Line 77, testNewDb.sp::T_LoadData
My bad, i edited the error. And I'm using that because I need to store the field index in a variable.
https://sm.alliedmods.net/new-api/db...FieldNameToNum
PyKw is offline
GetRektByNoob
Member
Join Date: Nov 2018
Old 08-20-2019 , 14:22   Re: Problem MySQL T_LoadData
Reply With Quote #4

afaik you are trying to find the field index but the result is not fetched try doing
Code:
 //If a row set was returned:
    if(results.FetchRow())
    {
	int valoareCol;
    	results.FieldNameToNum("valoare", valoareCol);
        valoare[client] = results.FetchInt(valoareCol);
    }
    else
    {
        //not found in db, insert data:
        char steamid[32]; GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
        char query[256]; Format(query, sizeof(query), "INSERT INTO jailbreak_test (steamid) VALUES ('%s') ON DUPLICATE KEY UPDATE steamid = '%s';", steamid, steamid);
        db.Query(T_Generic, query);
    }

Last edited by GetRektByNoob; 08-20-2019 at 14:22.
GetRektByNoob is offline
PyKw
Junior Member
Join Date: Jan 2012
Old 08-20-2019 , 18:49   Re: Problem MySQL T_LoadData
Reply With Quote #5

Quote:
Originally Posted by GetRektByNoob View Post
afaik you are trying to find the field index but the result is not fetched try doing
Code:
 //If a row set was returned:
    if(results.FetchRow())
    {
	int valoareCol;
    	results.FieldNameToNum("valoare", valoareCol);
        valoare[client] = results.FetchInt(valoareCol);
    }
    else
    {
        //not found in db, insert data:
        char steamid[32]; GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
        char query[256]; Format(query, sizeof(query), "INSERT INTO jailbreak_test (steamid) VALUES ('%s') ON DUPLICATE KEY UPDATE steamid = '%s';", steamid, steamid);
        db.Query(T_Generic, query);
    }
Now I'm getting this error:
Code:
L 08/21/2019 - 01:46:35: [SM] Exception reported: No current result set
L 08/21/2019 - 01:46:35: [SM] Blaming: testNewDb.smx
L 08/21/2019 - 01:46:35: [SM] Call stack trace:
L 08/21/2019 - 01:46:35: [SM]   [0] DBResultSet.FetchRow
L 08/21/2019 - 01:46:35: [SM]   [1] Line 84, testNewDb.sp::T_LoadData
PyKw is offline
GetRektByNoob
Member
Join Date: Nov 2018
Old 08-20-2019 , 20:02   Re: Problem MySQL T_LoadData
Reply With Quote #6

I'm sorry for the mistake but the error comes from the sql statement when doing update you dont actually select any field and which means the query table is empty and you can't find the field index

you need to use the select * statement instead
GetRektByNoob is offline
PyKw
Junior Member
Join Date: Jan 2012
Old 08-21-2019 , 15:00   Re: Problem MySQL T_LoadData
Reply With Quote #7

Quote:
Originally Posted by GetRektByNoob View Post
I'm sorry for the mistake but the error comes from the sql statement when doing update you dont actually select any field and which means the query table is empty and you can't find the field index

you need to use the select * statement instead
Can you please write it down, cause I don't get it!
PyKw is offline
ShD3luxe
Member
Join Date: Aug 2019
Location: Localhost
Old 08-21-2019 , 20:54   Re: Problem MySQL T_LoadData
Reply With Quote #8

Code:
	
public void OnClientDisconnect(int client)
{
	char query[256], steamid[32];
	GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
	FormatEx(query, sizeof(query), "UPDATE jailbreak_test SET valoare = %i WHERE steamid = '%s'", valoare[client], steamid);
	g_Database.Query(T_LoadData, query, GetClientUserId(client));
}
Update does not return a result set .
Use fast query for UPDATE,INSERT,DELETE (operations without a result set).
Code:
public void OnClientDisconnect(int client)
{
	char query[256], steamid[32];
	GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
	FormatEx(query, sizeof(query), "UPDATE jailbreak_test SET valoare = %i WHERE steamid = '%s'", valoare[client], steamid);
	SQL_LockDatabase(db);// lock the database until the update operation is done bcs you are using threaded operations with non-threaded
	bool execQueryResult = SQL_FastQuery(db, query);
	SQL_UnlockDatabase(db); // unlock it right after the operation is done to prevent a deadlock
	if (!execQueryResult) // returns true if the operation was successful , false if there was a query problem or invalid db handle
	{
		char error[255];
		SQL_GetError(db, error, sizeof(error));
		PrintToServer("Failed to query (error: %s)", error);
	}
}
Example from here -> https://wiki.alliedmods.net/SQL_(SourceMod_Scripting
Fast query doc -> https://sm.alliedmods.net/new-api/dbi/SQL_FastQuery
Note: SQL_FastQuery is a non-threaded querie so keep that in mind when you are using it with threaded queries.

or change the line
Code:
g_Database.Query(T_LoadData, query, GetClientUserId(client));  //from OnClientDisconnect where you have the update query

--->

db.Query(T_Generic, query);
Since you create the entry for the user when he is connected if he is not in the table (so u can just update it bcs it exists)
Also make sure to have a default column value for 'valoare' , maybe 0 since you store points or credits.

Last edited by ShD3luxe; 08-21-2019 at 22:28. Reason: doc
ShD3luxe is offline
GetRektByNoob
Member
Join Date: Nov 2018
Old 08-22-2019 , 05:08   Re: Problem MySQL T_LoadData
Reply With Quote #9

Quote:
Originally Posted by ShD3luxe View Post
Code:
	
public void OnClientDisconnect(int client)
{
	char query[256], steamid[32];
	GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
	FormatEx(query, sizeof(query), "UPDATE jailbreak_test SET valoare = %i WHERE steamid = '%s'", valoare[client], steamid);
	g_Database.Query(T_LoadData, query, GetClientUserId(client));
}
Update does not return a result set .
Use fast query for UPDATE,INSERT,DELETE (operations without a result set).
Code:
public void OnClientDisconnect(int client)
{
	char query[256], steamid[32];
	GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
	FormatEx(query, sizeof(query), "UPDATE jailbreak_test SET valoare = %i WHERE steamid = '%s'", valoare[client], steamid);
	SQL_LockDatabase(db);// lock the database until the update operation is done bcs you are using threaded operations with non-threaded
	bool execQueryResult = SQL_FastQuery(db, query);
	SQL_UnlockDatabase(db); // unlock it right after the operation is done to prevent a deadlock
	if (!execQueryResult) // returns true if the operation was successful , false if there was a query problem or invalid db handle
	{
		char error[255];
		SQL_GetError(db, error, sizeof(error));
		PrintToServer("Failed to query (error: %s)", error);
	}
}
Example from here -> https://wiki.alliedmods.net/SQL_(SourceMod_Scripting
Fast query doc -> https://sm.alliedmods.net/new-api/dbi/SQL_FastQuery
Note: SQL_FastQuery is a non-threaded querie so keep that in mind when you are using it with threaded queries.

or change the line
Code:
g_Database.Query(T_LoadData, query, GetClientUserId(client));  //from OnClientDisconnect where you have the update query

--->

db.Query(T_Generic, query);
Since you create the entry for the user when he is connected if he is not in the table (so u can just update it bcs it exists)
Also make sure to have a default column value for 'valoare' , maybe 0 since you store points or credits.
its always better to use the method map in general (Database.Query...) and not the query functions like FastQuery because then you dont have to use functions like GetError LockDatabase... and you dont have to worry about errors coming from not locking the database or something

Last edited by GetRektByNoob; 08-22-2019 at 05:09.
GetRektByNoob is offline
ShD3luxe
Member
Join Date: Aug 2019
Location: Localhost
Old 08-22-2019 , 05:42   Re: Problem MySQL T_LoadData
Reply With Quote #10

For a simple non-threaded database I prefer FastQuery , in his example mixing both might be a bad idea but that's a solution too .
ShD3luxe is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:46.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode