AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [SQL] Error (https://forums.alliedmods.net/showthread.php?t=318190)

Had3s99 08-18-2019 16:38

[SQL] Error
 
Hello,

I've my code :

Code:

public void T_SelectPlayerTime(Database db, DBResultSet results, const char[] error, any data) {
        int client = 0;

        if ((client = GetClientOfUserId(data)) == 0) {
                return;
        }
       
        if (results == null) {
                LogError("T_SelectPlayerTime failed! %s", error);
        }
        else if(results.RowCount == 0) {
                char l_sQuery[256];
       
                char l_sPseudo[64];
                char l_sSteamId[64];
               
                GetClientName(client, STRING(l_sPseudo));
                GetClientAuthId(client, AuthId_Steam2, STRING(l_sSteamId));
               
                Time[client] = 0;

                FormatEx(l_sQuery, sizeof(l_sQuery), "INSERT INTO `Time_Players` (Pseudo, SteamId) VALUES ('%s', '%s')", l_sPseudo, l_sSteamId);
                Dbase.Query(T_InsertPlayerTime, l_sQuery, _, DBPrio_Low);
        }
}

public void T_InsertPlayerTime(Database db, DBResultSet results, const char[] error, any data) {
        if (results == null) {
                LogError("T_InsertPlayerTime failed! %s", error);
        }
}

And i've this error :

Code:

L 08/18/2019 - 21:55:10: [csgo_timer.smx] T_InsertPlayerTime failed! You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ballz', 'STEAM_1:1:86693297')' at line 1
What is my error ?

Thanks,

Had3s99.

Farbror Godis 08-18-2019 16:43

Re: [SQL] Error
 
I think it may be the ' symbols. As a side note, make it a habit to use Database.Format for queries in the future.

Had3s99 08-18-2019 16:53

Re: [SQL] Error
 
Quote:

Originally Posted by Farbror Godis (Post 2663732)
I think it may be the ' symbols. As a side note, make it a habit to use Database.Format for queries in the future.

So i've edit like that :

Code:

FormatEx(l_sQuery, sizeof(l_sQuery), "INSERT INTO Time_Players (Pseudo, SteamId) VALUES ('%s', '%s')", l_sPseudo, l_sSteamId);
And do u have exemple about ur 'Database.Format' ?

I don't understand everything cause i'm not very good in english ^^

CrazyHackGUT 08-19-2019 01:18

Re: [SQL] Error
 
Quote:

Originally Posted by Had3s99 (Post 2663734)
And do u have exemple about ur 'Database.Format' ?

Code:

Dbase.Format(l_sQuery, sizeof(l_sQuery), "INSERT INTO Time_Players (Pseudo, SteamId) VALUES ('%s', '%s')", l_sPseudo, l_sSteamId);

8guawong 08-19-2019 02:49

Re: [SQL] Error
 
change

Code:

FormatEx(l_sQuery, sizeof(l_sQuery), "INSERT INTO `Time_Players` (Pseudo, SteamId) VALUES ('%s', '%s')", l_sPseudo, l_sSteamId);
to

Code:

FormatEx(l_sQuery, sizeof(l_sQuery), "INSERT INTO `Time_Players` (Pseudo, SteamId) VALUES (%s, %s)", l_sPseudo, l_sSteamId);
see if the above helps

Ilusion9 08-19-2019 05:02

Re: [SQL] Error
 
PHP Code:

Database.Format(l_sQuerysizeof(l_sQuery), "INSERT INTO `Time_Players` (Pseudo, SteamId) VALUES ('%s', '%s');"l_sPseudol_sSteamId); 


Had3s99 09-05-2019 19:32

Re: [SQL] Error
 
So to fix my problem i've do that :

Dbase.Escape(l_sPseudo, l_sPseudoESC, sizeof(l_sPseudoESC));

And thanks for the Dbase.Format i don't know that ^^

And for the charset 'utf8mb4' it's only available on sourcemod 1.10 ? ^^


All times are GMT -4. The time now is 05:42.

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