View Single Post
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