Raised This Month: $ Target: $400
 0% 

First Plugin, Need Guidance


Post New Thread Reply   
 
Thread Tools Display Modes
thatguyyoulove
Member
Join Date: Nov 2010
Location: North Texas
Old 05-01-2012 , 04:30   Re: First Plugin, Need Guidance
Reply With Quote #21

Hmm. I am having a weird issue with MySQL. It errors out on my semicolon delimited query with:
PHP Code:
You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE IF NOT EXISTS viper_event_matches (event_id INT(4), event_match INT' at line 1 
BUT the query works just fine if I copy/paste it into phpmyadmin.

Here is the query:
PHP Code:
CREATE TABLE IF NOT EXISTS viper_events (event_id INT(4NOT NULL auto_incrementevent_name VARCHAR(128), current_match INT(4NOT NULL DEFAULT '1'start_time DATETIMEend_time DATETIMEis_active TINYINT(1), PRIMARY KEY (event_id));CREATE TABLE IF NOT EXISTS viper_event_matches (event_id INT(4), event_match INT(4), client_steam VARCHAR(24), client_kills INT(4), client_deaths INT(4), gg_win TINYINT(1), PRIMARY KEY (event_idevent_matchclient_steam));CREATE TABLE IF NOT EXISTS viper_event_weapons (event_id INT(4), client_steam VARCHAR(24), client_tks INT(4NOT NULLclient_suicides INT(4NOT NULLknife_kills INT(4NOT NULLusp_kills INT(4NOT NULLglock_kills INT(4NOT NULLp228_kills INT(4NOT NULLdeagle_kills INT(4NOT NULLfiveseven_kills INT(4NOT NULLelite_kills INT(4NOT NULLm3_kills INT(4NOT NULLxm1014_kills INT(4NOT NULLmp5navy_kills INT(4NOT NULLtmp_kills INT(4NOT NULLp90_kills INT(4NOT NULLmac10_kills INT(4NOT NULLump45_kills INT(4NOT NULLgalil_kills INT(4NOT NULLfamas_kills INT(4NOT NULLm4a1_kills INT(4NOT NULLak47_kills INT(4NOT NULLaug_kills INT(4NOT NULLsg552_kills INT(4NOT NULLsg550_kills INT(4NOT NULLg3sg1_kills INT(4NOT NULLscout_kills INT(4NOT NULLawp_kills INT(4NOT NULLm249_kills INT(4NOT NULLhegrenade_kills INT(4NOT NULLPRIMARY KEY (client_steam));CREATE TABLE IF NOT EXISTS viper_event_players (client_steam VARCHAR(24), client_name VARCHAR(80), PRIMARY KEY (client_steam)); 
I have tried things like adding a space after the semicolon, removing the final semicolon, etc. to no avail. Now I COULD chain these queries through each others callbacks and get them to execute in succession and call me IsEventActive() in the last callback like:

PrepareDB()-> creates first table-> callback_PrepareDB-> creates second table-> callback_PrepareDB2-> creates thirdtable-> callback_PrepareDB3-> creates fourth table-> callback_PrepareDB-> calls IsEventActive()

But that seems terribly wasteful. Surely there is a way to feed delimited queries into SM, right?

Last edited by thatguyyoulove; 05-01-2012 at 04:31.
thatguyyoulove is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-01-2012 , 04:44   Re: First Plugin, Need Guidance
Reply With Quote #22

Quote:
Originally Posted by thatguyyoulove View Post
Surely there is a way to feed delimited queries into SM, right?
Quote:
Originally Posted by psychonic View Post
The implementation needs to be compiled with support for that specifically enabled. SM's mysql extension does not have it enabled afaik.
__________________
asherkin is offline
thatguyyoulove
Member
Join Date: Nov 2010
Location: North Texas
Old 05-01-2012 , 07:13   Re: First Plugin, Need Guidance
Reply With Quote #23

Ah, too bad! Glad I at least know why now, thanks. Off to chaining the functions it seems.
thatguyyoulove is offline
thatguyyoulove
Member
Join Date: Nov 2010
Location: North Texas
Old 05-01-2012 , 18:52   Re: First Plugin, Need Guidance
Reply With Quote #24

I'm experiencing an odd issue. A couple times a day I get this error:

Code:
"Error establishing database connection: Database driver for "viper_db" is "sqlite" and should be "mysql".
However my database is most definitely setup as mysql in databases.cfg. The error goes away as soon as the map changes and the plugin reloads, at least for several hours until the error crops up again.

It looks to me like it is no longer seeing that my config file has "viper_db" set as the value of the "viper_db_config" CVAR and is perhaps falling back to the default connection which is SQLite.

The relevant code is:

PHP Code:
public OnPluginStart()
{
    
//Create Commands
    
RegAdminCmd("sm_viperstart"Command_ViperStartADMFLAG_RCON"sm_viperstart [starts Viper system]");
    
RegAdminCmd("sm_viperstop"Command_ViperStopADMFLAG_RCON"sm_viperstop [stops Viper system]");

    
//Debug Commands
    
RegAdminCmd("sm_viperscores"Command_ViperScoresADMFLAG_RCON"sm_vipersscores [debug Viper system command to show scores]");
    
RegAdminCmd("sm_viperscores_save"Command_ViperScoresSaveADMFLAG_RCON,  "sm_vipersscores_save [debug command to submit scores to database immediately]");

    
//Hook End Events
    
HookEvent("player_death"Event_PlayerDeath);
    
HookEvent("gg_win"Event_GGWin); 
    
HookEvent("cs_win_panel_match"Event_CSWinPanelMatch);

    
//Create CVars
    
viper_db_hndl CreateConVar("viper_db_config""default""Database configuration to use for Viper Tournament System"FCVAR_PLUGIN);
    
viper_table_name_hndl CreateConVar("viper_table_config""viper_events""MySQL table to use for Viper Tournament System Events"FCVAR_PLUGIN);
    
viper_matches_table_name_hndl CreateConVar("viper_matches_table_config""viper_event_matches""MySQL table to use for Viper Tournament System Match Data. Don't change unless necessary."FCVAR_PLUGIN);
    
viper_weapons_table_name_hndl CreateConVar("viper_weapons_table_config""viper_event_weapons""MySQL table to use for Viper Tournament System Weapons Data. Don't change unless necessary."FCVAR_PLUGIN);
    
viper_players_table_name_hndl CreateConVar("viper_players_table_config""viper_event_players""MySQL table to use for Viper Tournament System Player Data. Don't change unless necessary."FCVAR_PLUGIN);
    
viper_event_name_hndl CreateConVar("viper_event_name""Viper Tournament""The human readable name for the event to be used."FCVAR_PLUGIN);
    
//viper_debug_hndl = CreateConVar("viper_debug", "0", "The human readable name for the event to be used.", FCVAR_PLUGIN, true, 0, true, 1);

    //Monitor CVar changes and execute accompanying functions
    
HookConVarChange(viper_db_hndlOnViperDBChange); 
    
HookConVarChange(viper_table_name_hndlOnViperDBChange); 
    
HookConVarChange(viper_matches_table_name_hndlOnViperDBChange); 
    
HookConVarChange(viper_weapons_table_name_hndlOnViperDBChange); 
    
HookConVarChange(viper_players_table_name_hndlOnViperDBChange); 
    
HookConVarChange(viper_event_name_hndlOnViperEventNameChange);

    
//Execute config file, or create if it does not exist.
    
AutoExecConfig(true"viper");

    
//Load table names into global vars for use by functions 
    
GetConVarString(viper_db_hndldb_configsizeof(db_config)); 
    
GetConVarString(viper_table_name_hndlviper_table_namesizeof(viper_table_name));
    
GetConVarString(viper_matches_table_name_hndlviper_matches_table_namesizeof(viper_matches_table_name));
    
GetConVarString(viper_weapons_table_name_hndlviper_weapons_table_namesizeof(viper_weapons_table_name));
    
GetConVarString(viper_players_table_name_hndlviper_players_table_namesizeof(viper_players_table_name));
    
//viper_debug_bool = GetConVarBool(viper_debug_hndl);

    //Set stats to recordable
    
viper_stats_yet_recorded_bool false;

    
//Connect to database
    
ConnectDB();

PHP Code:
public ConnectDB()
{
    
// Verify that the configuration is defined in databases.cfg 
    
if (!SQL_CheckConfig(db_config)) {
        
Viper_LogError("Database configuration \"%s\" does not exist"db_config);
    }

    
// Attempt to establish a connection
    
SQL_TConnect(Callback_SQL_OnConnectdb_config);

PHP Code:
public OnViperDBChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
    
GetConVarString(viper_db_hndldb_configsizeof(db_config)); 
    
GetConVarString(viper_table_name_hndlviper_table_namesizeof(viper_table_name));

    
GetConVarString(viper_matches_table_name_hndlviper_matches_table_namesizeof(viper_matches_table_name));
    
GetConVarString(viper_weapons_table_name_hndlviper_weapons_table_namesizeof(viper_weapons_table_name));
    
GetConVarString(viper_players_table_name_hndlviper_players_table_namesizeof(viper_players_table_name));

    
ConnectDB();
    
PrepareDB();

And the errors I am seeing are:
Code:
L 05/01/2012 - 16:05:41: SourceMod error session started
L 05/01/2012 - 16:05:41: Info (map "aim_ag_texture_city_advanced") (file "errors_20120501.log")
L 05/01/2012 - 16:05:41: [SM] Native "SQL_ReadDriver" reported: Invalid database Handle 1/0 (error: 4)
L 05/01/2012 - 16:05:41: [SM] Displaying call stack trace for plugin "viper.smx":
L 05/01/2012 - 16:05:41: [SM]   [0]  Line 124, /home/groups/sourcemod/upload_tmp/phpaKQm7v.sp::PrepareDB()
L 05/01/2012 - 16:05:41: [SM]   [1]  Line 488, /home/groups/sourcemod/upload_tmp/phpaKQm7v.sp::OnViperDBChange()
L 05/01/2012 - 16:05:41: [viper.smx] Error establishing database connection: Database driver for "viper_db" is "sqlite" and should be "mysql".
L 05/01/2012 - 16:05:41: [SM] Plugin encountered error 25: Call was aborted
L 05/01/2012 - 16:05:41: [SM] Native "SetFailState" reported: FATAL: Error establishing database connection: Database driver "viper_db" is "sqlite" and should be "mysql".
L 05/01/2012 - 16:05:41: [SM] Displaying call stack trace for plugin "viper.smx":
L 05/01/2012 - 16:05:41: [SM]   [0]  Line 129, /home/groups/sourcemod/upload_tmp/phpaKQm7v.sp::PrepareDB()
L 05/01/2012 - 16:05:41: [SM]   [1]  Line 116, /home/groups/sourcemod/upload_tmp/phpaKQm7v.sp::Callback_SQL_OnConnect()
L 05/01/2012 - 16:18:48: Error log file session closed.

Last edited by thatguyyoulove; 05-01-2012 at 18:54.
thatguyyoulove is offline
Reply



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 06:30.


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