AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQLx Tablename Variable problem (https://forums.alliedmods.net/showthread.php?t=49840)

raa 01-13-2007 22:24

SQLx Tablename Variable problem
 
I don't see how the plugin can't resolve the tablename

Code:

new g_sqlstats_table[64]

public plugin_cfg()
        {
        // Fetch the database info stated in sql.cfg
        get_cvar_string("amx_sql_host",g_host,63)
        get_cvar_string("amx_sql_user",g_user,63)
        get_cvar_string("amx_sql_pass",g_pass,63)
        get_cvar_string("amx_sql_db",g_db,63)
        get_cvar_string("amx_sqlstats_table", g_sqlstats_table,63)
       
        g_SqlTuple = SQL_MakeDbTuple(g_host,g_user,g_pass,g_db)
               
        // ok, we're ready to connect
        new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
        if(SqlConnection == Empty_Handle)
                // stop the plugin with an error message
        set_fail_state(g_Error)
       
        new Handle:CREATE[1]
        // we must now prepare some random queries
        CREATE[0] = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS `%s` (`authid` VARCHAR( 32 ) NOT NULL, `name` VARCHAR( 32 ) NOT NULL , `date` TIMESTAMP( 10 ) NOT NULL , `score` INT NOT NULL ,`kills` INT NOT NULL , `teamkills` INT NOT NULL, `deaths` INT NOT NULL , `hits` INT NOT NULL , `shots` INT NOT NULL , `headshots` INT NOT NULL , `efficiency` DOUBLE (19,2) DEFAULT NULL, `accuracy` double(19,2) default NULL,`accuracyHS` double(19,2) default NULL, PRIMARY KEY(`authid`))",g_sqlstats_table)
        for(new Count;Count < 1;Count++)
                {
                // run the queries, check if they were alright
                // note that you can run the same query multiple times
                // we are not doing this here, but it's nice to have
                if(!SQL_Execute(CREATE[Count]))
                        {
                        // if there were any problems
                        SQL_QueryError(CREATE[Count],g_Error,511)
                        set_fail_state(g_Error)
                }
               
                // close the handle
                SQL_FreeHandle(CREATE[Count])
               
               
                // you free everything with SQL_FreeHandle
                SQL_FreeHandle(SqlConnection)
        }
        return PLUGIN_CONTINUE
}

error logfile
Code:

L 01/13/2007 - 17:56:16: Start of error session.
L 01/13/2007 - 17:56:16: Info (map "de_dust2") (logfile "error_011307.log")
L 01/13/2007 - 17:56:16: [AMXX] Plugin ("SQLx_tut.amxx") is setting itself as failed.
L 01/13/2007 - 17:56:16: [AMXX] Plugin says: Incorrect table name ''
L 01/13/2007 - 17:56:16: [AMXX] Displaying debug trace (plugin "SQLx_tut.amxx")
L 01/13/2007 - 17:56:16: [AMXX] Run time error 1: forced exit
L 01/13/2007 - 17:56:16: [AMXX]    [0] SQLx_tut.sma::plugin_cfg (line 124)

And when I replace the `%s` with a name like "table1", in the "CREATE[0]" line, it logs an error saying incorrect table "mydatabase.table1".

The DBI line I'm trying to convert to SQLx is ;
Code:

dbi_query(g_dbc, "CREATE TABLE IF NOT EXISTS `%s` (`authid` VARCHAR( 32 ) NOT NULL, `name` VARCHAR( 32 ) NOT NULL , `date` TIMESTAMP( 10 ) NOT NULL , `score` INT NOT NULL ,`kills` INT NOT NULL , `teamkills` INT NOT NULL, `deaths` INT NOT NULL , `hits` INT NOT NULL , `shots` INT NOT NULL , `headshots` INT NOT NULL , `efficiency` DOUBLE (19,2) DEFAULT NULL, `accuracy` double(19,2) default NULL,`accuracyHS` double(19,2) default NULL, PRIMARY KEY(`authid`))", g_sqlstats_table)

teame06 01-13-2007 22:28

Re: SQLx Tablename Variable problem
 
Code:
    get_cvar_string("amx_sqlstats_table", g_sqlstats_table,63)         server_print("[SQLX] %s", g_sqlstats_table);     g_SqlTuple = SQL_MakeDbTuple(g_host,g_user,g_pass,g_db)

Make sure it doesn't contain no table name in the g_sqlstats_table. If it does contain nothing. Where are you executing g_sqlstats_table to enter the value?

raa 01-13-2007 23:52

Re: SQLx Tablename Variable problem
 
Not exactly sure what your asking.

um.. Are you asking where the actual tablename is being defined? If so, in sql.cfg.

if not, could clarify please?

teame06 01-13-2007 23:55

Re: SQLx Tablename Variable problem
 
Did you register the cvar amx_sqlstats_table?

raa 01-14-2007 01:45

Re: SQLx Tablename Variable problem
 
Quote:

Originally Posted by teame06 (Post 426965)
Did you register the cvar amx_sqlstats_table?

that did the trick.. thanks.. not surprised I missed that.


All times are GMT -4. The time now is 22:23.

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