AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question about SQLx (https://forums.alliedmods.net/showthread.php?t=77276)

TheRadiance 09-09-2008 12:16

Question about SQLx
 
I have a little problem with sql plugin (using <sqlx>)

My situation:
new Handle:query=SQL_PrepareQuery(sqlx,"Select `column1` from `db` where `column1`='111')

My Problem:if there is no query that contains 111(for example) i will get this:
Code:

L 09/30/2008 - 20:25:38: [MySQL] No result set in this query!
L 09/30/2008 - 20:25:38: [AMXX] Displaying debug trace (plugin "amx_hwid.amxx")
L 09/30/2008 - 20:25:38: [AMXX] Run time error 10: native error (native "SQL_FieldNameToNum")
L 09/30/2008 - 20:25:38: [AMXX]    [0] amx_hwid.sma::client_putinserver (line 80)

How i can avoid it? For example: if there is no query with 111, it will return in player's console that there is now 111(but not debug) and stops function.

Or what format of query request i should user?
thnx.

|PJ| Shorty 09-09-2008 18:03

Re: Question about SQLx
 
what i can see from your error message:
you donīt check if you got a result before you read the result.

see:
http://http://www.amxmodx.org/funcwi...o=func&id=1103
http://www.amxmodx.org/funcwiki.php?go=func&id=1108

what you show me from your code is not enough to say something.

TheRadiance 09-09-2008 21:33

Re: Question about SQLx
 
Quote:

what you show me from your code is not enough to say something.
PHP Code:


public client_putinserver(id)
{
    new 
info[32];new _info=get_user_info(id,"*hwID",info,31)
    if((!
_info)||(!get_user_flags(id)&&ADMIN_USER))
        return 
PLUGIN_HANDLED
    
new Handle:query=SQL_PrepareQuery(sqlx,"Select `hwid` from `%s` where `hwid`='%s'",table,info)
    
SQL_Execute(query)
    new 
_col=SQL_FieldNameToNum(query,"hwid")
    new 
buff[32]
    
SQL_ReadResult(query,_col,buff,31)
    if(
equali(buff,""))
        return 
PLUGIN_HANDLED
    server_cmd
("kick #%d [*myAC] You have been banned from this server.",get_user_userid(id))
    
SQL_FreeHandle(query)
    return 
PLUGIN_HANDLED


Quote:

you donīt check if you got a result before you read the result.
How i can do it?
Please, if not hard, can you give me a correct part of code with it?

danielkza 09-09-2008 21:46

Re: Question about SQLx
 
http://www.amxmodx.org/funcwiki.php?go=func&id=1108

|PJ| Shorty 09-09-2008 22:03

Re: Question about SQLx
 
PHP Code:

public client_putinserver(id

    new 
info[32];new _info=get_user_info(id,"*hwID",info,31
    if((!
_info)||(!get_user_flags(id)&&ADMIN_USER)) 
        return 
PLUGIN_HANDLED 
    
new Handle:query=SQL_PrepareQuery(sqlx,"Select `hwid` from `%s` where `hwid`='%s'",table,info
    
SQL_Execute(query)
    while(
SQL_MoreResults(query)) { //execute code as long as you have a result
        //new _col=SQL_FieldNameToNum(query,"hwid") // not needed, _col always 0
        
new buff[32
        
//SQL_ReadResult(query,_col,buff,31)
        
SQL_ReadResult(query,0,buff,31// you only select "hwid", _col = 0
        //if(equali(buff,"")) 
           //return PLUGIN_HANDLED 
        
server_cmd("kick #%d [*myAC] You have been banned from this server.",get_user_userid(id))
        
SQL_NextRow(query//switch to next result
    
}
    
SQL_FreeHandle(query
    return 
PLUGIN_HANDLED 



TheRadiance 09-10-2008 00:57

Re: Question about SQLx
 
big thnx, works :)


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

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