AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Passing parameters using SQL_ThreadQuery (https://forums.alliedmods.net/showthread.php?t=318949)

marcelowzd 10-01-2019 18:45

Passing parameters using SQL_ThreadQuery
 
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.

Natsheh 10-02-2019 10:18

Re: Passing parameters using SQL_ThreadQuery
 
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.

marcelowzd 10-02-2019 18:07

Re: Passing parameters using SQL_ThreadQuery
 
Quote:

Originally Posted by Natsheh (Post 2668574)
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

Bugsy 10-02-2019 19:14

Re: Passing parameters using SQL_ThreadQuery
 
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.

marcelowzd 10-02-2019 19:42

Re: Passing parameters using SQL_ThreadQuery
 
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;



Bugsy 10-02-2019 19:56

Re: Passing parameters using SQL_ThreadQuery
 
Is GetUserAccount( iClient, szAccount, charsmax( szAccount ) ); actually setting the users steam id in szAccount?

marcelowzd 10-02-2019 19:58

Re: Passing parameters using SQL_ThreadQuery
 
Quote:

Originally Posted by Bugsy (Post 2668627)
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.

Bugsy 10-02-2019 19:58

Re: Passing parameters using SQL_ThreadQuery
 
Try this:
PHP Code:

server_print"Starting process: %s %f %d" szAccount fTime iCategory );
SQL_StartProcessszAccountfTimeiCategory ); 


marcelowzd 10-02-2019 20:06

Re: Passing parameters using SQL_ThreadQuery
 
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


Bugsy 10-06-2019 13:14

Re: Passing parameters using SQL_ThreadQuery
 
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 ) ); 



All times are GMT -4. The time now is 04:28.

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