Raised This Month: $51 Target: $400
 12% 

Using two tables in one SQL database


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lt Llama
Senior Member
Join Date: Aug 2004
Old 02-14-2006 , 01:15   Using two tables in one SQL database
Reply With Quote #1

Im not shure I have done the right thing. My plugin reads and writes to two SQL tables. As I have coded it the plugin_init is calling two tasks with a slight delay to init and connect to db. Is this really necessary? Do I only need to connect once to the database and then I can query both tables when connected?

It works now, but occationally there is a connection error in one or both result handles for the db connection. This happened once when the server had a lot of players and it was laggy.

From plugin_init:
Code:
// Connect to dabatase and init tables set_task(5.0, "sql_init_ranks") set_task(7.0, "sql_init_maps")

Init table 1:
Code:
// Init the ranks database public sql_init_ranks() {     new host[64], username[32], password[32], dbname[32], error[32]     get_cvar_string("amx_sql_host",host,64)     get_cvar_string("amx_sql_user",username,32)     get_cvar_string("amx_sql_pass",password,32)     get_cvar_string("amx_sql_db",dbname,32)     dbcRanks = dbi_connect(host,username,password,dbname,error,32)     if (dbcRanks == SQL_FAILED) {         log_amx("[AMXX: SKILLRANK] SQL Connection Failed to table skillrank")         return PLUGIN_HANDLED     } else {     dbi_query(dbcRanks,"CREATE TABLE IF NOT EXISTS `skillrank` ( `steamId` VARCHAR(32) NOT NULL,`nickNames` VARCHAR(32) NOT NULL, `nFinnished` INT NOT NULL, `rankTotal` INT NOT NULL, `primaryRank` INT NOT NULL, PRIMARY KEY(`steamId`))")     }     dbi_free_result(resultRanks)     return PLUGIN_CONTINUE }

Init table 2:
Code:
// Init the maps database public sql_init_maps() {     new host[64], username[32], password[32], dbname[32], error[32]     get_cvar_string("amx_sql_host",host,64)     get_cvar_string("amx_sql_user",username,32)     get_cvar_string("amx_sql_pass",password,32)     get_cvar_string("amx_sql_db",dbname,32)     dbcMaps = dbi_connect(host,username,password,dbname,error,32)     if (dbcMaps == SQL_FAILED) {         log_amx("[AMXX: SKILLRANK] SQL Connection Failed to table skillmaps")         return PLUGIN_HANDLED     } else {     dbi_query(dbcMaps,"CREATE TABLE IF NOT EXISTS `skillmaps` ( `id` int(11) NOT NULL auto_increment, `steamId` VARCHAR(32) NOT NULL,`nickNames` VARCHAR(32) NOT NULL, `mapName` VARCHAR(32) NOT NULL, `playerClass` INT NOT NULL, `curDate` VARCHAR(10) NOT NULL, `curTime` VARCHAR(8) NOT NULL, `difficulty` INT NOT NULL, `runTime` INT NOT NULL, PRIMARY KEY(`id`))")     }     dbi_free_result(resultMaps)     return PLUGIN_CONTINUE }
Lt Llama is offline
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 02-14-2006 , 01:29  
Reply With Quote #2

You do only need 1 connection to the server. Both SQL quaries to different tables can be from the same SQL connection. (So long as their in the same database of course)
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
Lt Llama
Senior Member
Join Date: Aug 2004
Old 02-14-2006 , 01:39  
Reply With Quote #3

Quote:
Originally Posted by GHW_Chronic
You do only need 1 connection to the server. Both SQL quaries to different tables can be from the same SQL connection. (So long as their in the same database of course)
Thanks. I was afraid this could be a problem in the plugin.
So I can just change my two
Code:
new Sql:dbcRanks new Sql:dbcMaps

to one Sql handle?
Lt Llama is offline
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 02-14-2006 , 01:45  
Reply With Quote #4

yeah, should work.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 02-14-2006 , 06:33  
Reply With Quote #5

If you make that a global variable
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
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:36.


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