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