Thread: [Solved] MySQL and SQLITE
View Single Post
Author Message
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 07-05-2021 , 00:30   MySQL and SQLITE
Reply With Quote #1

Here I go again, I've read somewhere that I don't remember that using SQL_ThreadQuery in a plugin that uses Mysql and SQLITE at the same time would be problematic (and in fact it is), would there be any possibility of using it now in 2021?

Below I leave a small example of error.

PHP Code:
#include <amxmodx>
#include <sqlx>
#pragma defclasslib sqlite sqlite

#define PLUGIN  "New Plug-In"
#define VERSION "1.0"
#define AUTHOR  "Author"

#define CREATE "CREATE TABLE IF NOT EXISTS example (steamid varchar(32), name varchar(32));"
#define CREATE2 "CREATE TABLE IF NOT EXISTS example (steamid TEXT, name TEXT);"

new Handle:g_MySQL
new Handle:g_MySQLITE
new QueryError[512]

public 
plugin_init()
{
        
register_plugin(PLUGINVERSIONAUTHOR)

        
set_task(1.0"InitQueries")
}

public 
InitQueries()
{
        
SQL_SetAffinity("mysql")

        
g_MySQL SQL_MakeDbTuple(Host,User,Pass,Db)

        new 
szMysqlQuery[150]
        
formatex
        
(
                
szMysqlQuery,
                
charsmax(szMysqlQuery),
                
CREATE
        
)

        
SQL_ThreadQuery(g_MySQL,"InitialMySQL_Handler",szMysqlQuery)

        
SQL_SetAffinity("sqlite")

        
g_MySQLITE SQL_MakeDbTuple("""""""SQLITE")

        new 
szQuery[150]

        
formatex
        
(
                
szQuery,
                
charsmax(szQuery),
                
CREATE2
        
)

        
SQL_ThreadQuery(g_MySQLITE,"InitialSQLITE_Handler"szQuery)
}

public 
InitialSQLITE_Handler(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
        if(
FailState == TQUERY_CONNECT_FAILED)
                
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
        else if(
FailState == TQUERY_QUERY_FAILED)
        {
                
SQL_GetQueryString(Query,QueryError,charsmax(QueryError))
                
log_amx("Could not execute query ^"%s^"",QueryError)
        }

        if(!
SQL_NumRows(Query))
        {
                
server_print("No Results.")
        }
        else
                
server_print("Created.")

        return 
PLUGIN_HANDLED
}

public 
InitialMySQL_Handler(FailStateHandle:QueryError[], ErrcodeData[], DataSize)
{
        if(
FailState == TQUERY_CONNECT_FAILED)
                
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
        else if(
FailState == TQUERY_QUERY_FAILED)
        {
                
SQL_GetQueryString(Query,QueryError,charsmax(QueryError))
                
log_amx("Could not execute query ^"%s^"",QueryError)
        }

        if(!
SQL_NumRows(Query))
        {
                
server_print("No Results.")
        }
        else
                
server_print("Created.")

        return 
PLUGIN_HANDLED

Code:
L 07/05/2021 - 01:13:37: [SQLITE] Invalid query handle: 2
L 07/05/2021 - 01:13:37: [AMXX] Displaying debug trace (plugin "error.amxx", version "1.0")
L 07/05/2021 - 01:13:37: [AMXX] Run time error 10: native error (native "SQL_NumResults")
L 07/05/2021 - 01:13:37: [AMXX]    [0] error.sma::InitialMySQL_Handler (line 86)
As you can see, I set the driver to mysql, and ran the threadquery, right after I set the driver to sqlite to do the same with the other query, and as we can see the first query was sent to the handler with the sqlite driver.

Then they will tell me "put a 1 second task between them", yes it works, but there are more functions that can occur in the middle of the game that there is no way to control and set tasks, so I'm looking for a "solution".
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/

Last edited by iceeedr; 07-05-2021 at 19:50.
iceeedr is offline
Send a message via Skype™ to iceeedr