AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Sql Queries (https://forums.alliedmods.net/showthread.php?t=144217)

zeus 11-30-2010 15:11

Sql Queries
 
I have a big small problem...
I have this code
Code:

        new szTemp[1024];
        format(szTemp,charsmax(szTemp),
        "INSERT INTO `%s`
        (`authid`,`name`,`tkills`,`theadshots`,`deaths`)VALUES \
        ('%s','%s','0','0','0') \
        (`damage`,`points`,`c4p`,`c4d`)VALUES \
        ('0','0','0','0') \
        (`m4a1hs`,`ak47hs`,`awphs`,`famashs`,`galilhs`)VALUES \
        ('0','0','0','0','0') \
        (`knifehs`,`deaglehs`,`usphs`,`glockhs`)VALUES \
        ('0','0','0',0') \
        (`hekills`,`m4a1kills`,`ak47kills`,`awpkills`,`famaskills`)VALUES \
        ('0','0','0','0','0') \
        (`galilkills`,`knifekills`,`deaglekills`,`uspkills`,`glockkills`)VALUES \
        ('0','0','0','0','0') \
        (`status`)VALUES('%s');",
        gTn,gTn,szSteamId,szName,gTn,gTn,gTn,gTn,gTn,gTn,status);

How to make it work?:|, i'm rubbish at sql
The error I get is :
Code:

error 037 : invalid string ( possibly non-terminated string)

xPaw 11-30-2010 15:19

Re: Sql Queries
 
"INSERT INTO `%s`

You forget \

zeus 11-30-2010 16:33

Re: Sql Queries
 
That was solverd :), thx
But now I have another problem
Code:

Load Query failed. [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\' at line 1

Exolent[jNr] 11-30-2010 16:41

Re: Sql Queries
 
Code:

        new szTemp[1024];
        format(szTemp,charsmax(szTemp),
        "INSERT INTO `%s` \
        (`authid`,`name`,`tkills`,`theadshots`,`deaths \
        `damage`,`points`,`c4p`,`c4d` \
        `m4a1hs`,`ak47hs`,`awphs`,`famashs`,`galilhs` \
        `knifehs`,`deaglehs`,`usphs`,`glockhs` \
        `hekills`,`m4a1kills`,`ak47kills`,`awpkills`,`famaskills` \
        `galilkills`,`knifekills`,`deaglekills`,`uspkills`,`glockkills` \
        `status`) \
        VALUES \
        ('%s','%s','0','0','0' \
        '0','0','0','0' \
        '0','0','0','0','0' \
        '0','0','0',0' \
        '0','0','0','0','0' \
        '0','0','0','0','0' \
        '%s');",
        gTn,szSteamId,szName,status);


zeus 11-30-2010 17:32

Re: Sql Queries
 
I get these errors
Code:

L 12/01/2010 - 00:35:29: [MySQL] Invalid info tuple handle: 1
L 12/01/2010 - 00:35:29: [AMXX] Displaying debug trace (plugin "xpmod_tbdm_ham2.amxx")
L 12/01/2010 - 00:35:29: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 12/01/2010 - 00:35:29: [AMXX]    [0] xpmod_tbdm_ham2.sma::Load_MySql (line 150)
L 12/01/2010 - 00:35:29: [AMXX]    [1] xpmod_tbdm_ham2.sma::client_putinserver (line 267)
L 12/01/2010 - 00:36:48: [MySQL] Invalid info tuple handle: 1
L 12/01/2010 - 00:36:48: [AMXX] Displaying debug trace (plugin "xpmod_tbdm_ham2.amxx")
L 12/01/2010 - 00:36:48: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 12/01/2010 - 00:36:48: [AMXX]    [0] xpmod_tbdm_ham2.sma::Save_MySql (line 255)
L 12/01/2010 - 00:36:48: [AMXX]    [1] xpmod_tbdm_ham2.sma::client_disconnect (line 272)

This is the code
Code:

public Load_MySql(id)
{
    new szSteamId[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
   
    new Data[1]
    Data[0] = id
   
    format(szTemp,charsmax(szTemp),
    "SELECT * FROM `%s` \
    WHERE (`%s`.`authid` = '%s')",
    gTn,gTn,szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
   
    SQL_FreeHandle(g_SqlConnection)
}

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", Errcode, Error)
    }
    else if(FailState == TQUERY_QUERY_FAILED)
    {
        log_amx("Load Query failed. [%d] %s", Errcode, Error)
    }

    new id
    id = Data[0]
   
    if(SQL_NumResults(Query) < 1)
    {
        //.if there are no results found
       
        new szSteamId[32]
        get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
        new szName[32]
        get_user_name(id, szName, charsmax(szName)) // get user's name
       
        //  if its still pending we can't do anything with it
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED
           
        new status[10]
        if(is_user_connected(id))
        {
                status="Online"
        }
        else
        {
                status="Offline"
        }
        new szTemp[1024];
        format(szTemp,charsmax(szTemp),
        "INSERT INTO `%s` \
        (`authid`,`name`,`tkills`,`theadshots`,`deaths \
        `damage`,`points`,`c4p`,`c4d` \
        `m4a1hs`,`ak47hs`,`awphs`,`famashs`,`galilhs` \
        `knifehs`,`deaglehs`,`usphs`,`glockhs` \
        `hekills`,`m4a1kills`,`ak47kills`,`awpkills`,`famaskills` \
        `galilkills`,`knifekills`,`deaglekills`,`uspkills`,`glockkills` \
        `status`) \
        VALUES \
        ('%s','%s','0','0','0' \
        '0','0','0','0' \
        '0','0','0','0','0' \
        '0','0','0',0' \
        '0','0','0','0','0' \
        '0','0','0','0','0' \
        '%s');",
        gTn,gTn,szSteamId,szName,gTn,gTn,gTn,gTn,gTn,gTn,status);
    }
    else
    {
        // if there are results found
        g_iPoints[id]        = SQL_ReadResult(Query, 1)
    }
   
    return PLUGIN_HANDLED
}

public Save_MySql(id)
{
        new szSteamId[32],szTemp[1024]
        get_user_authid(id, szSteamId, charsmax(szSteamId))

        new status[10]
        if(is_user_connected(id))
        {
                status="Online"
        }
        else
        {
                status="Offline"
        }

        new szName[32]
        get_user_name(id, szName, charsmax(szName))

        format(szTemp,charsmax(szTemp),
        "UPDATE `%s` SET \
        (`name`='%s',`tkills`='%d',`theadshots`='%d',`deaths`='%d',`damage`='%d' \
        `c4p ='%d',`c4d ='%d' \
        `m4a1hs`='%d',`ak47hs`='%d',`awphs`='%d',`famashs`='%d',`galilhs`='%d' \
        `knifehs`='%d',`deaglehs`='%d',`usphs`='%d',`glockhs`='%d' \
        `hekills`='%d',`m4a1kills`='%d',`ak47kills`='%d',`awpkills`='%d' \
        `galilkills`='%d',`knifekills`='%d',`deaglekills`='%d',`uspkills`='%d' \
        `glockkills`='%d',`famaskills`='%d',`status`='%s',`points`='%i') \
        WHERE (`%s`.`authid`='%s')",
        gTn,szName,g_Kills[id],g_TotalHs[id],g_Deaths[id],g_Damage[id],
        g_BombsPlanted[id],g_BombsDefused[id],g_M4a1Hs[id],g_Ak47Hs[id],g_AwpHs[id],
        g_FamasHs[id],g_GalilHs[id],g_KnifeHs[id],g_DeagleHs[id],g_UspHs[id],
        g_GlockHs[id],g_HeKills[id],g_M4a1Kills[id],g_Ak47Kills[id],g_AwpKills[id],
        g_GalilKills[id],g_KnifeKills[id],g_DeagleKills[id],g_UspKills[id],g_GlockKills[id],
        g_FamasKills[id],status,g_iPoints[id],gTn,szSteamId)

        SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

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


Exolent[jNr] 11-30-2010 17:43

Re: Sql Queries
 
I edited my post above.
You had too many formatting variables, so I removed to what it should be.

zeus 11-30-2010 18:05

Re: Sql Queries
 
Code:

L 12/01/2010 - 01:03:05: [MySQL] Invalid handle: 2
L 12/01/2010 - 01:03:05: [AMXX] Displaying debug trace (plugin "xpmod_tbdm_ham2.amxx")
L 12/01/2010 - 01:03:05: [AMXX] Run time error 10: native error (native "SQL_FreeHandle")
L 12/01/2010 - 01:03:05: [AMXX]    [0] xpmod_tbdm_ham2.sma::Load_MySql (line 152)
L 12/01/2010 - 01:03:05: [AMXX]    [1] xpmod_tbdm_ham2.sma::client_putinserver (line 267)

At line 152 I have this
Code:

SQL_FreeHandle(g_SqlConnection)
And at line 267 I have this
Code:

Load_MySql(id)

meTaLiCroSS 11-30-2010 18:20

Re: Sql Queries
 
Show here the lines on that g_SqlConnection is used.

zeus 11-30-2010 18:26

Re: Sql Queries
 
Code:

new Handle:g_SqlConnection
public MySql_Init()
{
    g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
    new ErrorCode
    g_SqlConnection=SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(g_SqlConnection == Empty_Handle)
        set_fail_state(g_Error)
    SQL_FreeHandle(g_SqlConnection)
}

public Load_MySql(id)
{
    new szSteamId[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
   
    new Data[1]
    Data[0] = id
   
    format(szTemp,charsmax(szTemp),
    "SELECT * FROM `%s` \
    WHERE (`%s`.`authid` = '%s')",
    gTn,gTn,szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
   
    SQL_FreeHandle(g_SqlConnection)
}


meTaLiCroSS 11-30-2010 18:29

Re: Sql Queries
 
The SQL_FreeHandle usage on Load_MySql function is totally useless. Why did you put that line there, if no connection stablished?


All times are GMT -4. The time now is 11:20.

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