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

SQL_FieldNameToNum cached value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 08-19-2013 , 09:18   SQL_FieldNameToNum cached value
Reply With Quote #1

For example i have:
PHP Code:
public MySqlFunctionFailStateHandle:QueryError[ ], ErrcodeData[ ], DataSize )
{
    switch( 
FailState )
    {
        case 
TQUERY_CONNECT_FAILED:
        {
           
set_fail_state"TQUERY_CONNECT_FAILED" )
        }
        
        case 
TQUERY_QUERY_FAILED:
        {
            
set_fail_state"TQUERY_QUERY_FAILED" )
        }
    }
    
    if( 
Errcode )
    {
        
set_fail_state"ERRCODE" )
    }

    new 
id
    id 
Data]
    
    if( ~
IsConnectedid ) )
        return 
PLUGIN_HANDLED
    
    
if( SQL_NumResultsQuery ) < )
    {
        
// do something else
    
}
    else
    {
        
g_iPlayerValueid ] = SQL_ReadResultQuerySQL_FieldNameToNumQuery"player_value" ) )
    }

    return 
PLUGIN_CONTINUE

will not better if i cached value for SQL_FieldNameToNum ? (for optimization) Example:
PHP Code:
public MySqlFunctionFailStateHandle:QueryError[ ], ErrcodeData[ ], DataSize )
{
    switch( 
FailState )
    {
        case 
TQUERY_CONNECT_FAILED:
        {
           
set_fail_state"TQUERY_CONNECT_FAILED" )
        }
        
        case 
TQUERY_QUERY_FAILED:
        {
            
set_fail_state"TQUERY_QUERY_FAILED" )
        }
    }
    
    if( 
Errcode )
    {
        
set_fail_state"ERRCODE" )
    }

    new 
id
    id 
Data]
    
    if( ~
IsConnectedid ) )
        return 
PLUGIN_HANDLED
    
    
if( SQL_NumResultsQuery ) < )
    {
        
// do something else
    
}
    else
    {
        static 
iValue
        
if( !iValue iValue SQL_FieldNameToNumQuery"player_value" )
        
        
g_iPlayerValueid ] = SQL_ReadResultQueryiValue )
    }

    return 
PLUGIN_CONTINUE

but i don't know why sometimes when used method 2 (with cached value iValue) i get error:
Code:
[MySQL] Invalid column: -1
[AMXX] Run time error 10: native error (native "SQL_ReadResult")
Thanks.
dFF is offline
aaarnas
Veteran Member
Join Date: Jun 2008
Location: Lithuania
Old 08-19-2013 , 15:40   Re: SQL_FieldNameToNum cached value
Reply With Quote #2

Best:
SELECT player_value FROM ...

g_iPlayerValue[ id ] = SQL_ReadResult(Query, 0)

Just write all needed columns in query and then just type column number. Starts from 0.
SQL_FieldNameToNum is needed to use when using '*' for columns (All columns), and you don't know order. Or for removing hardcoding.
__________________
My plugins:
[ZP] ZM_VIP (v2.0.0 is comming. v1.9.1 BETA is out!)

aaarnas 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 05:22.


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