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

Need help with sql and amxx.


Post New Thread Reply   
 
Thread Tools Display Modes
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 08-27-2019 , 07:11   Re: Need help with sql and amxx.
Reply With Quote #11

It's most likely you pass incorrect info to tuple
__________________
Airkish is offline
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
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-27-2019 , 08:33   Re: Need help with sql and amxx.
Reply With Quote #13

What will this print?
new szSteamId[32]
get_user_authid(id, szSteamId, 32)

Also on insert, put a space before values
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
xd346
Junior Member
Join Date: Aug 2019
Old 08-27-2019 , 09:03   Re: Need help with sql and amxx.
Reply With Quote #14

Quote:
Originally Posted by JocAnis View Post
What will this print?
new szSteamId[32]
get_user_authid(id, szSteamId, 32)
It just prints my steam id.

Quote:
Originally Posted by JocAnis View Post
Also on insert, put a space before values
Added a space before VALUES, still getting the same error.
xd346 is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-27-2019 , 09:27   Re: Need help with sql and amxx.
Reply With Quote #15

ye i know its for steamid, but i though maybe you will get somthing wrong because of buffer size

when i was doing SQLite, my connection info was always: "", "", "", "esf_data" (but i guess its the same with your typed info)

i would also delete 'test.' prefixes on your queries, dont know why you need them when u have only one table..but it seems its a problem in a connecting to the database not the queries idk..
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
xd346
Junior Member
Join Date: Aug 2019
Old 08-27-2019 , 09:41   Re: Need help with sql and amxx.
Reply With Quote #16

Quote:
Originally Posted by JocAnis View Post
ye i know its for steamid, but i though maybe you will get somthing wrong because of buffer size

when i was doing SQLite, my connection info was always: "", "", "", "esf_data" (but i guess its the same with your typed info)

i would also delete 'test.' prefixes on your queries, dont know why you need them when u have only one table..but it seems its a problem in a connecting to the database not the queries idk..
Must be something wrong with the connection somehow cause it gives me the same error with incorrect info.
xd346 is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-27-2019 , 10:52   Re: Need help with sql and amxx.
Reply With Quote #17

Maybe your sql module is not loaded
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
xd346
Junior Member
Join Date: Aug 2019
Old 08-27-2019 , 11:09   Re: Need help with sql and amxx.
Reply With Quote #18

Quote:
Originally Posted by JocAnis View Post
Maybe your sql module is not loaded
Both mysql and sqlite are enabled in modules.ini if that's what you're referring to.
xd346 is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-27-2019 , 11:41   Re: Need help with sql and amxx.
Reply With Quote #19

ok, do you have your sql file in amxmodx/data/sqlite3/ ?

if not, try with:

g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
->
g_SqlTuple = SQL_MakeDbTuple( "", "", "", "esf_data" )

if that also doesnt help, im out
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 08-27-2019 at 11:41.
JocAnis is offline
xd346
Junior Member
Join Date: Aug 2019
Old 08-27-2019 , 11:52   Re: Need help with sql and amxx.
Reply With Quote #20

Quote:
Originally Posted by JocAnis View Post
ok, do you have your sql file in amxmodx/data/sqlite3/ ?

if not, try with:

g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
->
g_SqlTuple = SQL_MakeDbTuple( "", "", "", "esf_data" )

if that also doesnt help, im out
I have a esf_data.sq3 file in there.
xd346 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 06:57.


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