Raised This Month: $ Target: $400
 0% 

Problem MySQL T_LoadData


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

Any idea what I'm doing wrong here?

Code:
#include <sourcemod>
int valoare[MAXPLAYERS + 1] = {0, ...};
Database g_Database = null;

public Plugin myinfo = 
{
	name = "Test Plugin",
	author = "Picutz",
	description = "",
	version = "1.0",
	url = "http://steamcommunity.com/profiles/76561198453137840"
}

public OnPluginStart()
{
	RegConsoleCmd("sm_setvaloare", SetValoare);
	Database.Connect(T_Connect);
}

public Action SetValoare(client, args)
{
	char arg[64];
	GetCmdArg(1, arg, sizeof(arg));
	valoare[client] = StringToInt(arg);
	PrintToChat(client, "Ai setat valoarea pe %d", StringToInt(arg));
}

public void T_Connect(Database db, const char[] error, any data)
{
    if(db == null)
    {
        LogError("Database failure: %s", error);
    }
	else
	{
		g_Database = db;
	}
}

public void OnClientAuthorized(int client)
{
    //idk if querying from a steamid of BOT is a great idea
    if(!IsFakeClient(client) && g_Database != null)
    {
        char query[256], steamid[32];
        GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
        FormatEx(query, sizeof(query), "SELECT * FROM jailbreak_test WHERE steamid = '%s'", steamid);
        g_Database.Query(T_LoadData, query, GetClientUserId(client));

        //TQuery will send the following to the threaded callback:
        //Database = db
        //Results = results
    }
}

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));
}

public void T_LoadData(Database db, DBResultSet results, const char[] error, any data)
{
    //If either are broken:
    if(db == null || results == null)
    {
        LogError("T_LoadData returned error: %s", error);
        return;
    }

    int client = GetClientOfUserId(data); 

    int valoareCol;
    results.FieldNameToNum("valoare", valoareCol);

    //If a row set was returned:
    if(results.FetchRow())
    {
        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);
    }
}

//THIS IS OUR OTHER COOL CALLBACK TO JUST DO NICE QUERIES WITHOUT RETURNED DATA!
public void T_Generic(Database db, DBResultSet results, const char[] error, any data)
{
    if(db == null || results == null)
    {
        LogError("T_Generic returned error: %s", error);
        return;
    }
}
I get error in logs:
Code:
L 08/20/2019 - 19:43:27: [SM] Exception reported: No current result set
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
Line 77:
Quote:
results.FieldNameToNum("valoare", valoareCol);
Database: https://imgur.com/a/4hMjbJe

Last edited by DarkDeviL; 03-23-2021 at 03:49. Reason: Restore to previous version.
PyKw is offline
 



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 01:20.


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