View Single Post
xd346
Junior Member
Join Date: Aug 2019
Old 08-27-2019 , 07:20   Re: Need help with sql and amxx.
Reply With Quote #12

Quote:
Originally Posted by Airkish View Post
It's most likely you pass incorrect info to tuple
Corrected it. Still the same error:


PHP Code:
L 08/27/2019 13:18:54: [MySQLInvalid info tuple handle0
L 08
/27/2019 13:18:54: [AMXXDisplaying debug trace (plugin "DBContentSQLX.amxx")
L 08/27/2019 13:18:54: [AMXXRun time error 10native error (native "SQL_ThreadQuery")
L 08/27/2019 13:18:54: [AMXX]    [0DBContentSQLX.sma::Load_MySql (line 58)
L 08/27/2019 13:18:54: [AMXX]    [1DBContentSQLX.sma::client_putinserver (line 115
code:
PHP Code:
#include <amxmodx> 
#include <sqlx>
#include <ipci\ascend> 
#include <esf_util> 
#include <fun> 
#include <fakemeta> 
#include <fakemeta_const> 
#include <hamsandwich>  

new Handle:g_SqlTuple
new g_Error[512]
new 
iExp[32]

new 
Host[]     = "127.0.0.1"
new User[]    = "root"
new Pass[]     = ""
new Db[]     = "esf_data"

public plugin_init()  

  
register_plugin("Database Data","1.0",""
  
register_clcmd("say steamid","plugintriggertest"); 
  
RegisterHam(Ham_Killed"player""fwdPlayerDeath"0);
  
  
set_task(1.0"MySql_Init")


public 
MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,512)
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
       
    new 
Handle:Queries
    Queries 
SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS test (steamid varchar(32),pl INT(12))")

    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queries,g_Error,512)
        
set_fail_state(g_Error)
    }
    
    
SQL_FreeHandle(Queries)

    
SQL_FreeHandle(SqlConnection)   
}

public 
Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamId32)
    
    new 
Data[1]
    
Data[0] = id

    format
(szTemp,512,"SELECT * FROM test WHERE (test.steamid = '%s')"szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}


public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }

    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) < 1
    {
        new 
szSteamId[32]
        
get_user_authid(idszSteamId32)
        if (
equal(szSteamId,"ID_PENDING"))
            return 
PLUGIN_HANDLED
            
        
new szTemp[512]

        
format(szTemp,512,"INSERT INTO test ( steamid , pl)VALUES ('%s','0');",szSteamId)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else 
    {
        
// if there are results found
        
iExp[id]         = SQL_ReadResult(Query1)
    }
    
    return 
PLUGIN_HANDLED
}

public 
Save_MySql(id)
{
    new 
szSteamId[32], szName[32], szTemp[512]
    
get_user_authid(idszSteamId32)

    
format(szTemp,512,"UPDATE test SET pl = '%i' WHERE test.steamid = '%s';",iExp[id], szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
    
Load_MySql(id)
}

public 
client_disconnect(id)
{
    
Save_MySql(id)
}

//ignore this part
new steamid[32
new 
username[40
new 
powerlevel 
new charactername[32
new 
characterid  

public plugintriggertest(id

    
get_user_name(id,username,40
    
get_user_authididsteamid32)
    
getClassDATAvcharacteridcxNamecharactername32 ); 


Last edited by xd346; 08-27-2019 at 08:48.
xd346 is offline