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

SQL_FetchString, problem, or?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BlackJack
Member
Join Date: Mar 2013
Old 07-08-2013 , 12:59   SQL_FetchString, problem, or?
Reply With Quote #1

Hello.

With MySQL I have learned to work, but I have a little problem.

This is my code:

PHP Code:
public OnClientPutInServer(client)
{
    new 
String:auth[32];
    new 
String:steam_id[24];
    
GetClientAuthString(clientauthsizeof(auth));
    new 
String:query1[150];
    new 
String:query2[150];
    
    
Format(query2sizeof(query2), "SELECT `steam_id` FROM `bodovysystem` WHERE steam_id='%s'"auth);    
    new 
Handle:queryQ SQL_Query(g_databasequery2);
    
SQL_FetchString(queryQ0steam_idsizeof(steam_id));

    if (!
StrEqual(authsteam_idtrue))
    {
        if(!
StrEqual(auth""true))
        {    
            
Format(query1sizeof(query1), "INSERT INTO `bodovysystem`(`steam_id`, `body`) VALUES ('%s',0)"auth);    
            new 
Handle:queryH SQL_Query(g_databasequery1);
            
            if (
queryH == INVALID_HANDLE)
            {
                new 
String:error[100]
                
SQL_GetError(g_databaseerrorsizeof(error));
                
PrintToChat(client,"[JB] Databaza je momentalne nedostupna, Chyba: %s"error);
            }
        }
    }    

When a client first time connect on server, this code save his SteamId32 to Database. And when client connect second time, server detects it and does not writes it to the database.

This part is working (i tested):

PHP Code:
if (!StrEqual(authsteam_idtrue))
    {
        if(!
StrEqual(auth""true))
        {    
            
Format(query1sizeof(query1), "INSERT INTO `bodovysystem`(`steam_id`, `body`) VALUES ('%s',0)"auth);    
            new 
Handle:queryH SQL_Query(g_databasequery1);
            
            if (
queryH == INVALID_HANDLE)
            {
                new 
String:error[100]
                
SQL_GetError(g_databaseerrorsizeof(error));
                
PrintToChat(client,"[JB] Databaza je momentalne nedostupna, Chyba: %s"error);
            }
        }
    }    

This also work:

PHP Code:
new String:auth[32];
    new 
String:steam_id[24];
    
GetClientAuthString(clientauthsizeof(auth));
    new 
String:query1[150];
    new 
String:query2[150]; 
But i have problem with this:

PHP Code:
Format(query2sizeof(query2), "SELECT `steam_id` FROM `bodovysystem` WHERE steam_id='%s'"auth);    
    new 
Handle:queryQ SQL_Query(g_databasequery2);
    
SQL_FetchString(queryQ0steam_idsizeof(steam_id));

    if (!
StrEqual(authsteam_idtrue))
    {
....
....
.... 
And anyway I do not know what's the problem. When I write that last part, plugin does not work.

Last edited by BlackJack; 07-08-2013 at 13:01.
BlackJack is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 07-08-2013 , 14:07   Re: SQL_FetchString, problem, or?
Reply With Quote #2

Format(query2, sizeof(query2), "SELECT `steam_id` FROM `bodovysystem` WHERE steam_id='%s'", auth);

What are you trying to do with this?
xf117 is offline
Send a message via ICQ to xf117
BlackJack
Member
Join Date: Mar 2013
Old 07-08-2013 , 14:17   Re: SQL_FetchString, problem, or?
Reply With Quote #3

Select STEAM ID from the database ("STEAM_ID") and compare it with the "auth". Oh, wait, something I do not sit there. If "STEAM_ID" is not in the database, so there is nothing to return. Is that right?

This is new code:

PHP Code:
new String:auth[32];
    
GetClientAuthString(clientauthsizeof(auth));
    new 
String:query1[150];
    new 
String:query2[150];
    
    
Format(query2sizeof(query2), "SELECT `steam_id` FROM `bodovysystem` WHERE steam_id='%s'"auth);    
    new 
Handle:queryQ SQL_Query(g_databasequery2);
    
    if (
queryQ == INVALID_HANDLE)
    {
        if(!
StrEqual(auth""true))
        {    
            
Format(query1sizeof(query1), "INSERT INTO `bodovysystem`(`steam_id`, `body`) VALUES ('%s',0)"auth);    
            new 
Handle:queryH SQL_Query(g_databasequery1);
            
            if (
queryH == INVALID_HANDLE)
            {
                new 
String:error[100]
                
SQL_GetError(g_databaseerrorsizeof(error));
                
PrintToChat(client,"[JB] Databaza je momentalne nedostupna, Chyba: %s"error);
            }
        }
    } 
    else
    {
        
PrintToServer("Mate problem");
    } 
The message "PrintToServer("Mate problem");" shows still.

Last edited by BlackJack; 07-08-2013 at 14:42.
BlackJack is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 07-08-2013 , 14:42   Re: SQL_FetchString, problem, or?
Reply With Quote #4

I'm saying, you are trying to get steam id from a database WHERE steam id is the same as the one you specify. Anyway, use this check to be sure database does return you something to fetch
PHP Code:
Format(query2sizeof(query2), "SELECT `steam_id` FROM `bodovysystem` WHERE steam_id='%s'"auth);
new 
Handle:queryQ SQL_Query(g_databasequery2);
if (
SQL_FetchRow(queryQ)) {
    
SQL_FetchString(queryQ0steam_idsizeof(steam_id));
} else {
    
// There is no such steam id in your database
}

if (!
StrEqual(authsteam_idtrue)) {
    
// your code ... 

Last edited by xf117; 07-08-2013 at 14:43.
xf117 is offline
Send a message via ICQ to xf117
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 07-08-2013 , 14:59   Re: SQL_FetchString, problem, or?
Reply With Quote #5

You may want to rewrite this code to utilize threaded queries so it doesn't crash/lag server on slow/no response.
__________________
thetwistedpanda is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 07-09-2013 , 13:49   Re: SQL_FetchString, problem, or?
Reply With Quote #6

And again, someone does not realize that GetClientAuthString is failable and returns bool...
Dr. Greg House is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-09-2013 , 14:09   Re: SQL_FetchString, problem, or?
Reply With Quote #7

How to do it correctly:
Code:
SELECT EXISTS(SELECT 1 FROM bodovysystem WHERE steam_id = '%s' LIMIT 1)

Last edited by Chrisber; 07-09-2013 at 14:10.
Chrisber is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 07-09-2013 , 14:33   Re: SQL_FetchString, problem, or?
Reply With Quote #8

Quote:
Originally Posted by Dr. Greg House View Post
And again, someone does not realize that GetClientAuthString is failable and returns bool...
Or succeeded, but returns an unusable SteamID like STEAM_ID_PENDING.
__________________
11530 is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 07-10-2013 , 05:15   Re: SQL_FetchString, problem, or?
Reply With Quote #9

Does OnClientAuthorized may also fail sometimes?
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
mcpan313
Senior Member
Join Date: Mar 2010
Old 07-10-2013 , 06:07   Re: SQL_FetchString, problem, or?
Reply With Quote #10

PHP Code:
public OnClientAuthorized(client, const String:auth[])
{
    if (
IsFakeClient(client))
    {
        return;
    }

    
decl String:szQuery[256];

    
FormatEx(szQuerysizeof(szQuery),
        
"INSERT INTO bodovysystem (steam_id, body) \
        SELECT * FROM (SELECT '%s', 0) AS tmp \
        WHERE NOT EXISTS \
        (SELECT steam_id FROM bodovysystem WHERE steam_id='%s') \
        LIMIT 1;"
,
        
authauth);
    
    
SQL_TQuery(g_databaseSQLTCallback_GetErrorszQuery);
}

public 
SQLTCallback_GetError(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    if (
hndl == INVALID_HANDLE)
    {
        
LogError("SQLERROR=%s"error);
    }


Last edited by mcpan313; 07-10-2013 at 06:23.
mcpan313 is offline
Send a message via MSN to mcpan313
Reply



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 11:24.


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