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

Return a value from SQL ThreadQuery


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
retard
Junior Member
Join Date: Sep 2010
Old 11-09-2010 , 08:19   Return a value from SQL ThreadQuery
Reply With Quote #1

I have been studying few of the tutorials around here because I need a permanent gag plugin for my server with MySQL support. I have started editing one gag plugin and I'm currently stuck at this part:



PHP Code:
public CheckGagid
{
    static 
szAuthid35 ];
    
get_user_authididszAuthid34 );
    
    static 
szQuery128 ];
    
formatexszQuery127"SELECT `GagDate` FROM `Players` WHERE `SteamID` = '%s';"szAuthid );
    
    new 
iData];
    
iData] = ENCODE_TEXTszAuthid );
    
    new 
isGagged SQL_ThreadQueryg_SqlTuple"QueryCheckGag"szQueryiData2);
    
    
    
server_print("iData: %i"isGagged)
    
    return 
PLUGIN_CONTINUE;


public 
QueryCheckGagiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime 
{

    switch( 
iFailState ) {
        case 
TQUERY_CONNECT_FAILED: {
            
log_amx"Connection failed: %s"szError);
        }
        case 
TQUERY_QUERY_FAILED: {
            
log_amx"Query failed: %s"szError );
        }
        default: {
            new 
iTimeStamp SQL_ReadResulthQuery);
            
log_amx("current time: %i, timestamp :%i"get_systime(), iTimeStamp)
            
            new 
iMonthiDayiYeariHouriMinuteiSecond;
            
            
UnixToTimeiTimeStamp iYear iMonth iDay iHour iMinute iSecond );
            
            static 
szNewId35 ];
            
DECODE_TEXTiData], szNewId34 )
            
            new 
pid str_to_num(szNewId)
            
            
client_print(pidprint_chat"Gagged until: %02d/%02d/%02d %02d:%02d:%02d"  iYear iMonth iDay iHour iMinute iSecond );
            
            if( 
get_systime( ) >= iTimeStamp ) {
                
                static 
szQuery128 ];
                
formatexszQuery127"DELETE FROM `Players` WHERE `SteamID` = '%s';"szNewId  );
                
                
SQL_ThreadQueryg_SqlTuple"QueryDeleteGag"szQuery )


            }
            
        }
        
    }
    
    
}

public 
QueryDeleteGagiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime ) {
    switch( 
iFailState ) {
        case 
TQUERY_CONNECT_FAILED: {
            
log_amx"Connection failed: %s"szError);
        }
        case 
TQUERY_QUERY_FAILED: {
            
log_amx"Query failed: %s"szError );
        }
        default: {
            
            
        }
        
        
    }
    
    

The problem is that SQL_ThreadQuery always returns 1. I've tried it this way but still returns 1
PHP Code:
public CheckGagid )
{
    static 
szAuthid35 ];
    
get_user_authididszAuthid34 );
    
    static 
szQuery128 ];
    
formatexszQuery127"SELECT `GagDate` FROM `Players` WHERE `SteamID` = '%s';"szAuthid );
    
    new 
iData];
    
iData] = ENCODE_TEXTszAuthid );
    
    new 
iGag SQL_ThreadQueryg_SqlTuple"QueryCheckGag"szQueryiData2);
    
server_print("iGag: %i"iGag);
    
    if ( 
iGag == // gagged
    
{
        return 
PLUGIN_HANDLED;
    }
    
    
    return 
PLUGIN_CONTINUE;


public 
QueryCheckGagiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime 
{

    switch( 
iFailState ) {
        case 
TQUERY_CONNECT_FAILED: {
            
log_amx"Connection failed: %s"szError);
        }
        case 
TQUERY_QUERY_FAILED: {
            
log_amx"Query failed: %s"szError );
        }
        default: {
            new 
iTimeStamp SQL_ReadResulthQuery);
            
log_amx("current time: %i, timestamp :%i"get_systime(), iTimeStamp)
            
            new 
iMonthiDayiYeariHouriMinuteiSecond;
            
            
UnixToTimeiTimeStamp iYear iMonth iDay iHour iMinute iSecond );
            
            static 
szNewId35 ];
            
DECODE_TEXTiData], szNewId34 )
            new 
pid str_to_num(szNewId)
            
            
client_print(pidprint_chat"Gag until: %02d/%02d/%02d  %02d:%02d:%02d"  iYear iMonth iDay iHour iMinute iSecond );
            if( 
get_systime( ) >= iTimeStamp ) {
                
                static 
szQuery128 ];
                
formatexszQuery127"DELETE FROM `Players` WHERE `SteamID` = '%s';"szNewId  );
                
                
SQL_ThreadQueryg_SqlTuple"QueryDeleteGag"szQuery )
                return 
0;
                
            }
            
        }
        
    }

return 
1;
    
    


Last edited by retard; 11-09-2010 at 10:52.
retard is offline
undrex
Junior Member
Join Date: Jan 2008
Location: Sweden
Old 11-09-2010 , 09:40   Re: Return a value from SQL ThreadQuery
Reply With Quote #2

PHP Code:
if ( (time() - iTimeStamp) >= 120 ) {

}

//120 = num of seconds before gag should expire 
if the UnixToTime function does what it sounds like then i guess you have a unix_timestamp in your db so try code above
undrex is offline
retard
Junior Member
Join Date: Sep 2010
Old 11-09-2010 , 10:50   Re: Return a value from SQL ThreadQuery
Reply With Quote #3

Quote:
Originally Posted by undrex View Post
PHP Code:
if ( (time() - iTimeStamp) >= 120 ) {

}

//120 = num of seconds before gag should expire 
if the UnixToTime function does what it sounds like then i guess you have a unix_timestamp in your db so try code above
Have I explained myself that poorly? The time check works completly fine, I have checked that. However, the return value is always 1. I guess I am not able to return values from threads?
retard is offline
issen1
Member
Join Date: Jan 2010
Old 11-09-2010 , 11:12   Re: Return a value from SQL ThreadQuery
Reply With Quote #4

Obviously you can't, because the function SQL_ThreadQuery returns immediately (see docs for return value) and your callback function is only called later, when the Query was executed (or failed).
__________________
greets (:
issen1 is offline
retard
Junior Member
Join Date: Sep 2010
Old 11-09-2010 , 11:20   Re: Return a value from SQL ThreadQuery
Reply With Quote #5

Quote:
Originally Posted by issen1 View Post
Obviously you can't, because the function SQL_ThreadQuery returns immediately (see docs for return value) and your callback function is only called later, when the Query was executed (or failed).
I see. How do I deal with this problem then? I'm kinda lost at this point...
retard is offline
issen1
Member
Join Date: Jan 2010
Old 11-09-2010 , 12:01   Re: Return a value from SQL ThreadQuery
Reply With Quote #6

What are you trying to do? Blocking a message depending upon the return value of the MySQL query? That won't be possible.

You can either block the message entirely and print your own message in the query handler or just let the message through.
__________________
greets (:
issen1 is offline
retard
Junior Member
Join Date: Sep 2010
Old 11-09-2010 , 12:56   Re: Return a value from SQL ThreadQuery
Reply With Quote #7

Quote:
Originally Posted by issen1 View Post
What are you trying to do? Blocking a message depending upon the return value of the MySQL query? That won't be possible.

You can either block the message entirely and print your own message in the query handler or just let the message through.
Yeah. The MySQL Query checks if the player is gagged. I guess I will have to use a Trie to store the gagged players. Will do a query whenever a player connects if he's in the db, if yes then add him to the Trie. Thought I could do it without the use of an array/trie and simply do queries whenever required, oh well. Thanks for your help.

Last edited by retard; 11-09-2010 at 13:00.
retard is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-09-2010 , 16:22   Re: Return a value from SQL ThreadQuery
Reply With Quote #8

You can't use SQL_ThreadQuery() for instant results.
Therefore, you have to execute the query normally using the SQL_Connect() + SQL_PrepareQuery() + SQL_Execute() method or cache the value of a player being gagged.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
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 17:57.


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