AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with SQLx (https://forums.alliedmods.net/showthread.php?t=225406)

huntex 09-04-2013 09:40

Problem with SQLx
 
Hello. I have a problem. I writing a plugin for CS 1.6, which check messages and nicknames for advertising (regular expressions). RegEx patterns contains in the database and updating one time in the function plugin_cfg ().

There are about 10 tables.
7 contains patterns.
1 log table
2 ban tables

Most SQL read/write requests executes on log and ban tables (if plugin has found advertising at chat message).

Problem: This plugin makes random server's crash only after changelevel.

I tried various versions of amxmodx & server's builds, but it didn't help.

Code (reduced):
Code:

new Handle:SQL_Tuple
new Handle:SQL_Connection

public plugin_init()
{
        register_cvar("ar_sql_host", "127.0.0.1")
        // ...
}

public plugin_end()
{
        SQL_FreeHandle(SQL_Connection)
        SQL_FreeHandle(SQL_Tuple)
}

public plugin_cfg()
{
        get_cvar_string("ar_sql_host",host,30)
        // ...
       
        // SQL CONNECTION ========================================================================================
        SQL_Tuple = SQL_MakeDbTuple(host,user,pass,dbase)
        new err, error[256]
        SQL_Connection = SQL_Connect(SQL_Tuple, err, error, charsmax(error))
       
        if(SQL_Connection != Empty_Handle)
        {
                log_amx("[SQLx connect ok]")
        }
        else
        {
                log_amx("[SQLX sql error] %s ",error)
                pause("a")
        }
        // ========================================================================================================
       
        // loading regex pattenrs form tables (one time)
}

// sql function example
public sql_get_ucp_table_id(ucpid[9])
{
        if(SQL_Connection == Empty_Handle) return -1
       
        new Handle:query = SQL_PrepareQuery(SQL_Connection,"SELECT id FROM `%s` WHERE ucp = '%s'", ucps_table, ucpid)
        SQL_Execute(query)
       
        if (SQL_NumResults(query) > 0)
        {
                new result = SQL_ReadResult(query, 0)
                SQL_FreeHandle(query)
               
                return result
        }
       
        SQL_FreeHandle(query)
        return -1
}


SpaWn2KiLl 09-05-2013 21:36

Re: Problem with SQLx
 
Try this:

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <sqlx>

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

new Handle:MYSQL_Tuple
new Handle:MYSQL_Connect

new szHostname[50], szUsername[50], szPassword[50], szDatabase[50]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
hostname register_cvar("Host""")
    
username register_cvar("Username""")
    
password register_cvar("Password""")
    
database register_cvar("DataBase""")
    
    
MYSQL_Load()
}

public 
plugin_end()
{
    
MYSQL_Close
}

public 
MYSQL_Load()
{
    new 
szError[512], szErr

    MYSQL_Tuple 
SQL_MakeDbTuple(szHostnameszUsernameszPasswordszDatabase)
    
MYSQL_ConnectSQL_Connect(MYSQL_TupleszErrszErrorcharsmaxszError ))

    if(
MYSQL_Connect == Empty_Handle)
        
set_fail_stateszError )
}

public 
MYSQL_Close()
{
    
SQL_FreeHandle(MYSQL_Connect)




All times are GMT -4. The time now is 19:08.

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