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

Solved Passing parameters using SQL_ThreadQuery


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
marcelowzd
Senior Member
Join Date: Feb 2011
Location: São Paulo, Brazil
Old 10-01-2019 , 18:45   Passing parameters using SQL_ThreadQuery
Reply With Quote #1

Hi guys, i'm trying to pass parameters to SQL_ThreadQuery (not the query itself), but when i try to retrieve them, i get random values

PHP Code:
enum _:eData
{
    
ACCOUNTSTEAM_MAX_SIZE ],
    
Float:TIME,
    
CATEGORY
};

public 
SQL_StartProcessszAccountSTEAM_MAX_SIZE ], Float:fTimeiCategory )
{
    new 
szQuery128 ], aDataeData ];

    
aDataACCOUNT ] = szAccount;
    
aDataTIME ] = fTime;
    
aDataCATEGORY ] = iCategory;

    
log_amx"%s %f %i"aDataACCOUNT ], aDataTIME ], aDataCATEGORY ] );

    
formatexszQuerycharsmaxszQuery ), "SELECT CD_Top, FL_Time FROM Tops WHERE NM_ACCOUNT LIKE '%s' AND NM_MAP LIKE '%s' AND CD_CATEGORY = %i"szAccountg_szMapNameiCategory  );

    
SQL_ThreadQueryg_hSqlTuple"SearchResult"szQueryaDatasizeof aData );
}

public 
SearchResultiFailStateHandle:hQueryszError[ ], aDataeData ], iSize )
{
    if( 
iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED )
    {
        new 
szLogFile64 ];

        
formatexszLogFilecharsmaxszLogFile ), "events/TopsSQL.txt" );

        
log_to_fileszLogFile"[Tops SQL] Erro identificado" );
        
log_to_fileszLogFile"[Tops SQL] %s"szError );

        return 
PLUGIN_CONTINUE;
    }

    new 
szAccountSTEAM_MAX_SIZE ], Float:fTimeiCategory;

    
szAccount aDataACCOUNT ];
    
fTime aDataTIME ];
    
iCategory aDataCATEGORY ];

    
log_amx"%s %f %i"aDataACCOUNT ], aDataTIME ], aDataCATEGORY ] );

    return 
PLUGIN_CONTINUE;

Outputs
Code:
L 10/01/2019 - 19:36:49: [Test.amxx] STEAM_0:1:39264654 15.058460 5 // FIRST LOG
L 10/01/2019 - 19:36:49: [Test.amxx]  0.000000 95 // SECOND LOG
Am i doing something wrong?

Thanks in advance.
__________________

Last edited by Bugsy; 10-08-2019 at 20:28.
marcelowzd is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-02-2019 , 10:18   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #2

aData[ ACCOUNT ] = szAccount

That's not how you fill up an array, correct way is to use copy or formatex

Doing this way may result in filling just the first cell since the compiler is stupid it will assume that you did aData[ACCOUNT][0] = szAccount [0]

So do this for all copy(aData[ ACCOUNT ], charsmax(aData[ ACCOUNT ]), szAccount) instead and test again.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 10-02-2019 at 17:33.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
marcelowzd
Senior Member
Join Date: Feb 2011
Location: São Paulo, Brazil
Old 10-02-2019 , 18:07   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
aData[ ACCOUNT ] = szAccount

That's not how you fill up an array, correct way is to use copy or formatex

Doing this way may result in filling just the first cell since the compiler is stupid it will assume that you did aData[ACCOUNT][0] = szAccount [0]

So do this for all copy(aData[ ACCOUNT ], charsmax(aData[ ACCOUNT ]), szAccount) instead and test again.
Just tried with both copy and formatex, and they are producing the same outputs. Tried also in new game instead of SteamCMD HLDS just to be sure and also the same. I'm using AMXX 1.9.0 dev 5215, i'll try a newer one to see if anything changes.

This has happened to me before, but i have no idea how i fixed it, if i even did it to be honest
__________________
marcelowzd is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-02-2019 , 19:14   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #4

If you are not formatting, always use copy(). There is no reason why Natsheh's recommendation wouldn't work. There has to be something else in your code that you are not including that is causing an issue.
__________________
Bugsy is offline
marcelowzd
Senior Member
Join Date: Feb 2011
Location: São Paulo, Brazil
Old 10-02-2019 , 19:42   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #5

Full code

PHP Code:
#include < amxmodx >
#include < sqlx >
#include < KzAPI >
#include < MapType >
#include < FpsLimiter >

new g_iMapType MAP_TYPE_BHOP;

new 
Handle:g_hSqlTuple;

new 
g_szMapName32 ];

enum _:eData
{
    
ACCOUNTSTEAM_MAX_SIZE ],
    
Float:TIME,
    
CATEGORY
};

public 
OnMapTypeSelectediMapType ){ g_iMapType iMapType; } // One Line Function

public plugin_init( )
{
    new const 
szPlugin[ ] = "Tops - SQL";
    new const 
szVersion[ ] = "0.0.1";
    new const 
szAuthor[ ] = "SQL Test";

    
register_pluginszPluginszVersionszAuthor );
}

public 
plugin_precache( )
{
    new const 
szHost[ ] = "localhost";
    new const 
szUser[ ] = "root";
    new const 
szPass[ ] = "root";
    new const 
szDtbs[ ] = "Servidor";

    
g_hSqlTuple SQL_MakeDbTupleszHostszUserszPassszDtbs );

    
get_mapnameg_szMapNamecharsmaxg_szMapName ) );
}

public 
kz_finishclimbiClientFloat:fTimeiCheckPointsiGoChecksiWeaponiBhopMode )
{
     if( 
iGoChecks == && ( iWeapon == CSW_USP || iWeapon == CSW_KNIFE ) )
    {
        new 
iFPS get_user_fpsiClient );

        if( 
iFPS >= 500 )
            return 
PLUGIN_CONTINUE;

        new 
iCategoryszAccountSTEAM_MAX_SIZE ];

        
GetUserAccountiClientszAccountcharsmaxszAccount ) );

        switch( 
iBhopMode )
        {
            case 
BH_SPEED_FPS: { iCategory GetCategoryiFPS ); }
            case 
BH_SPEED_CRAZYSPEED: { iCategory 6; }
            case 
BH_SPEED_HIGHCRAZY: { iCategory 7; }
            case 
BH_SPEED_2KRUN:{ iCategory 8; }
        }

        
SQL_StartProcessszAccountfTimeiCategory );
    }

    return 
PLUGIN_CONTINUE;
}

public 
SQL_StartProcessszAccountSTEAM_MAX_SIZE ], Float:fTimeiCategory )
{
    new 
szQuery128 ], aDataeData ];

    
copyaDataACCOUNT ], charsmaxaDataACCOUNT ] ), szAccount );

    
//aData[ ACCOUNT ] = szAccount;
    
aDataTIME ] = fTime;
    
aDataCATEGORY ] = iCategory;

    
log_amx"%s %f %i"aDataACCOUNT ], aDataTIME ], aDataCATEGORY ] );

    
formatexszQuerycharsmaxszQuery ), "SELECT CD_Top, FL_Time FROM Tops WHERE NM_ACCOUNT LIKE '%s' AND NM_MAP LIKE '%s' AND CD_CATEGORY = %i"szAccountg_szMapNameiCategory  );

    
SQL_ThreadQueryg_hSqlTuple"SearchResult"szQueryaDatasizeof aData );
}

public 
SearchResultiFailStateHandle:hQueryszError[ ], aDataeData ], iSize )
{
    if( 
iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED )
    {
        new 
szLogFile64 ];

        
formatexszLogFilecharsmaxszLogFile ), "events/TopsSQL.txt" );

        
log_to_fileszLogFile"[Tops SQL] Erro identificado" );
        
log_to_fileszLogFile"[Tops SQL] %s"szError );

        return 
PLUGIN_CONTINUE;
    }

    new 
szAccountSTEAM_MAX_SIZE ], Float:fTimeiCategory;

    
copyszAccountcharsmaxszAccount ), aDataACCOUNT ] );
    
//szAccount = aData[ ACCOUNT ];
    
fTime aDataTIME ];
    
iCategory aDataCATEGORY ];

    
log_amx"%s %f %i"aDataACCOUNT ], aDataTIME ], aDataCATEGORY ] );

    new 
iNum SQL_NumResultshQuery );

    if( 
iNum // Usuário já tem um tempo, comparar com o anterior
    
{

    }
    else 
// Usuário não tem um tempo, inserir no banco
    
{
        new 
szQuery128 ];

        
formatexszQuerycharsmaxszQuery ), "INSERT INTO Tops VALUES ( NULL, '%s', '%f', '%s', %i )"szAccountfTimeg_szMapNameiCategory );

        
log_amxszQuery );

        
SQL_ThreadQueryg_hSqlTuple"InsertResult"szQueryaDatasizeof aData );
    }

    return 
PLUGIN_CONTINUE;
}

public 
InsertResultiFailStateHandle:hQueryszError[ ], aDataeData ], iSize )
{
    if( 
iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED )
    {
        new 
szLogFile64 ];

        
formatexszLogFilecharsmaxszLogFile ), "events/TopsSQL.txt" );

        
log_to_fileszLogFile"[Tops SQL] Erro identificado" );
        
log_to_fileszLogFile"[Tops SQL] %s"szError );

        return 
PLUGIN_CONTINUE;
    }

    
log_amx"Inserido com sucesso!" );

    return 
PLUGIN_CONTINUE;
}

public 
plugin_end( )
{
    
SQL_FreeHandleg_hSqlTuple );
}

GetCategoryiFPS )
{
    new 
iCategory;

    switch( 
iFPS )
    {
        case 
100: { iCategory 0; }
        case 
125: { iCategory 1; }
        case 
131: { iCategory 2; }
        case 
200: { iCategory 3; }
        case 
250: { iCategory 4; }
        case 
333: { iCategory 5; }
    }

    return 
iCategory;

__________________

Last edited by marcelowzd; 10-02-2019 at 19:45.
marcelowzd is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-02-2019 , 19:56   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #6

Is GetUserAccount( iClient, szAccount, charsmax( szAccount ) ); actually setting the users steam id in szAccount?
__________________
Bugsy is offline
marcelowzd
Senior Member
Join Date: Feb 2011
Location: São Paulo, Brazil
Old 10-02-2019 , 19:58   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
Is GetUserAccount( iClient, szAccount, charsmax( szAccount ) ); actually setting the users steam id in szAccount?
I guess so, since the first output is my actual steamid, as stated in the first post

PHP Code:
 log_amx"%s %f %i"aDataACCOUNT ], aDataTIME ], aDataCATEGORY ] ); 
Code:
L 10/01/2019 - 19:36:49: [Test.amxx] STEAM_0:1:39264654 15.058460 5 // FIRST LOG
L 10/01/2019 - 19:36:49: [Test.amxx]  0.000000 95 // SECOND LOG
There are more outputs as shown in the code, but these are related to the queries. Also, time and category are also different.
__________________

Last edited by marcelowzd; 10-02-2019 at 20:00.
marcelowzd is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-02-2019 , 19:58   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #8

Try this:
PHP Code:
server_print"Starting process: %s %f %d" szAccount fTime iCategory );
SQL_StartProcessszAccountfTimeiCategory ); 
__________________
Bugsy is offline
marcelowzd
Senior Member
Join Date: Feb 2011
Location: São Paulo, Brazil
Old 10-02-2019 , 20:06   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #9

PHP Code:
Starting processSTEAM_0:1:39264654 16.976419 5
L 10
/02/2019 21:04:58: [Test.amxxSTEAM_0:1:39264654 16.976419 5
L 10
/02/2019 21:05:00: [Test.amxxErro identificado
L 10
/02/2019 21:05:00: [Test.amxxCan't connect to MySQL server on 'localhost' (10061) 
PHP Code:
Starting processSTEAM_0:1:3926465 10.613281 5
L 10
/02/2019 21:31:21: [Test.amxxSTEAM_0:1:3926465 10.613281 5
L 10
/02/2019 21:31:21: [Test.amxx]  0.000000 95
L 10
/02/2019 21:31:21: [Test.amxxINSERT INTO Tops VALUES NULL'''0.000000''bhop_allspark'95 )
L 10/02/2019 21:31:21: [Test.amxxInserido com sucesso
Sorry, took me some time to realize i had mysql off

UPDATE: Updating AMXX to 1.9.0 +dev5249 didn't help. I don't really understand why this happens and it's the second time it does this kind of stuff, which stops me from using this kind of enumerations. I'll try this plugin in my Linux Server even though it doesn't have mysql just to see if the parameters can be read.

UPDATE 2: Output on server is even worse
Code:
L 10/03/2019 - 19:43:49: [Test.amxx] STEAM_0:1:39264654 31.307519 5
L 10/03/2019 - 19:43:49: [Test.amxx] // Completely blank
L 10/03/2019 - 19:46:00: [Test.amxx] Erro Identificado
L 10/03/2019 - 19:46:00: [Test.amxx] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
UPDATE 3: Tried with this simple code and this gives the correct output, it's just in SQL_ThreadQuery that i'm getting this problem
PHP Code:
public VarTest( )
{
    new 
aDataeData ];

    
copyaDataACCOUNT ], charsmaxaDataACCOUNT ] ), "STEAM_0:1:39264654" );
    
    
aDataTIME ] = 5.0;
    
aDataCATEGORY ] = 1;

    
log_amx"function 1 - %s %f %i"aDataACCOUNT ], aDataTIME ], aDataCATEGORY ] );

    
VarTest2aData );
}

public 
VarTest2aDataeData ] )
{
    
log_amx"function 2 - %s %f %i"aDataACCOUNT ], aDataTIME ], aDataCATEGORY ] );

Code:
L 10/04/2019 - 23:13:54: [Test.amxx] function 1 - STEAM_0:1:3926465 5.000000 1
L 10/04/2019 - 23:13:54: [Test.amxx] function 2 - STEAM_0:1:3926465 5.000000 1
__________________

Last edited by marcelowzd; 10-04-2019 at 22:17.
marcelowzd is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-06-2019 , 13:14   Re: Passing parameters using SQL_ThreadQuery
Reply With Quote #10

Maybe SQL_ThreadQuery() isn't able to handle an enumerator-sized array that contains string(s). I've personally passed data in the past using the below. Try doing a test, eliminating the string portion of your enumerator and see if it works. If it does, we can probably figure out a workaround.

Edit: I just tested it myself and enum sized arrays, that include strings, pass to the callback handler perfectly.
PHP Code:

enum QueryTypes
{
    
qtPlayerConnected,
    
qtPlayerDisconnected,
    
qtGetNewAdmins,
    
qtGetNewPermAdmins,
    
qtSetPlayerAsAdmin,
    
qtRemoveAllAdmins,
    
qtPruneDatabase,
    
qtShowStats,
    
qtShowTop15
}

enum _:QueryInfo
{
    
QueryTypes:qiQueryType,
    
qiPlayerID
}

new 
QueryDataQueryInfo ];
QueryDataqiQueryType ] = qtPlayerConnected;
QueryDataqiPlayerID ] = id;
formatexg_szBuffer charsmaxg_szBuffer ) , Query_PlayerConnected pdDataid ][ pdAuthID ] );
SQL_ThreadQueryg_SQLTuple "QueryHandle" g_szBuffer QueryData sizeofQueryData ) ); 
__________________

Last edited by Bugsy; 10-06-2019 at 14:47.
Bugsy is offline
Reply


Thread Tools
Display Modes

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


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