From fce65e8e42db9f28354c70d3f2e2e765ebaa1b3a Mon Sep 17 00:00:00 2001 From: skull132 Date: Sun, 21 Jun 2015 17:34:28 +0300 Subject: [PATCH] SQL backstage update Since Aurora only has one SQL database, I've removed the old database proc and object (dbcon_old). It'll make everything connect to the same database, and be less of a hassle with the config files. --- code/controllers/configuration.dm | 6 ---- code/defines/procs/statistics.dm | 6 ++-- code/global.dm | 7 ---- code/modules/library/lib_machines.dm | 24 ++++++------- code/world.dm | 50 ++-------------------------- 5 files changed, 18 insertions(+), 75 deletions(-) diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index 7d375413..8d05d1b6 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -608,12 +608,6 @@ sqllogin = value if ("password") sqlpass = value - if ("feedback_database") - sqlfdbkdb = value - if ("feedback_login") - sqlfdbklogin = value - if ("feedback_password") - sqlfdbkpass = value if ("enable_stat_tracking") sqllogging = 1 else diff --git a/code/defines/procs/statistics.dm b/code/defines/procs/statistics.dm index e30a444f..8791e247 100644 --- a/code/defines/procs/statistics.dm +++ b/code/defines/procs/statistics.dm @@ -10,7 +10,7 @@ proc/sql_poll_players() log_game("SQL ERROR during player polling. Failed to connect.") else var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss") - var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO population (playercount, time) VALUES ([playercount], '[sqltime]')") + var/DBQuery/query = dbcon.NewQuery("INSERT INTO population (playercount, time) VALUES ([playercount], '[sqltime]')") if(!query.Execute()) var/err = query.ErrorMsg() log_game("SQL ERROR during player polling. Error : \[[err]\]\n") @@ -24,7 +24,7 @@ proc/sql_poll_admins() log_game("SQL ERROR during admin polling. Failed to connect.") else var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss") - var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO population (admincount, time) VALUES ([admincount], '[sqltime]')") + var/DBQuery/query = dbcon.NewQuery("INSERT INTO population (admincount, time) VALUES ([admincount], '[sqltime]')") if(!query.Execute()) var/err = query.ErrorMsg() log_game("SQL ERROR during admin polling. Error : \[[err]\]\n") @@ -49,7 +49,7 @@ proc/sql_poll_population() log_game("SQL ERROR during population polling. Failed to connect.") else var/sqltime = time2text(world.realtime, "YYYY-MM-DD hh:mm:ss") - var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO population (playercount, admincount, time) VALUES ([playercount], [admincount], '[sqltime]')") + var/DBQuery/query = dbcon.NewQuery("INSERT INTO population (playercount, admincount, time) VALUES ([playercount], [admincount], '[sqltime]')") if(!query.Execute()) var/err = query.ErrorMsg() log_game("SQL ERROR during population polling. Error: \[[err]\]\n") diff --git a/code/global.dm b/code/global.dm index 6baaf9f9..70160f33 100644 --- a/code/global.dm +++ b/code/global.dm @@ -234,12 +234,6 @@ var/sqldb = "tgstation" var/sqllogin = "root" var/sqlpass = "" - // Feedback gathering sql connection - -var/sqlfdbkdb = "test" -var/sqlfdbklogin = "root" -var/sqlfdbkpass = "" - var/sqllogging = 0 // Should we log deaths, population stats, etc? @@ -264,7 +258,6 @@ var/custom_event_msg = null //Database connections //A connection is established on world creation. Ideally, the connection dies when the server restarts (After feedback logging.). var/DBConnection/dbcon = new() //Feedback database (New database) -var/DBConnection/dbcon_old = new() //Tgstation database (Old database) - See the files in the SQL folder for information what goes where. // Reference list for disposal sort junctions. Filled up by sorting junction's New() /var/list/tagger_locations = list() diff --git a/code/modules/library/lib_machines.dm b/code/modules/library/lib_machines.dm index 4701adfe..1cd3ed82 100644 --- a/code/modules/library/lib_machines.dm +++ b/code/modules/library/lib_machines.dm @@ -43,8 +43,8 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f Filter by Author: [author]
\[Start Search\]
"} if(1) - establish_old_db_connection() - if(!dbcon_old.IsConnected()) + establish_db_connection() + if(!dbcon.IsConnected()) dat += "ERROR: Unable to contact External Archive. Please contact your system administrator for assistance.
" else if(!SQLquery) dat += "ERROR: Malformed search request. Please contact your system administrator for assistance.
" @@ -52,7 +52,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f dat += {""} - var/DBQuery/query = dbcon_old.NewQuery(SQLquery) + var/DBQuery/query = dbcon.NewQuery(SQLquery) query.Execute() while(query.NextRow()) @@ -189,15 +189,15 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f (Return to main menu)
"} if(4) dat += "

External Archive

" - establish_old_db_connection() - if(!dbcon_old.IsConnected()) + establish_db_connection() + if(!dbcon.IsConnected()) dat += "ERROR: Unable to contact External Archive. Please contact your system administrator for assistance." else dat += {"(Order book by SS13BN)

AUTHORTITLECATEGORYSS13BN
"} - var/DBQuery/query = dbcon_old.NewQuery("SELECT id, author, title, category FROM library") + var/DBQuery/query = dbcon.NewQuery("SELECT id, author, title, category FROM library") query.Execute() while(query.NextRow()) @@ -332,8 +332,8 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f if(scanner.cache.unique) alert("This book has been rejected from the database. Aborting!") else - establish_old_db_connection() - if(!dbcon_old.IsConnected()) + establish_db_connection() + if(!dbcon.IsConnected()) alert("Connection to Archive has been severed. Aborting.") else /* @@ -347,7 +347,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f var/sqlcontent = sanitizeSQL(scanner.cache.dat) var/sqlcategory = sanitizeSQL(upload_category) var/sqluploader = sanitizeSQL(usr.key) - var/DBQuery/query = dbcon_old.NewQuery("INSERT INTO library (author, title, content, category, uploadtime, uploader) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]', Now(), '[sqluploader]')") + var/DBQuery/query = dbcon.NewQuery("INSERT INTO library (author, title, content, category, uploadtime, uploader) VALUES ('[sqlauthor]', '[sqltitle]', '[sqlcontent]', '[sqlcategory]', Now(), '[sqluploader]')") if(!query.Execute()) usr << query.ErrorMsg() else @@ -356,8 +356,8 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f if(href_list["targetid"]) var/sqlid = sanitizeSQL(href_list["targetid"]) - establish_old_db_connection() - if(!dbcon_old.IsConnected()) + establish_db_connection() + if(!dbcon.IsConnected()) alert("Connection to Archive has been severed. Aborting.") if(bibledelay) for (var/mob/V in hearers(src)) @@ -366,7 +366,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f bibledelay = 1 spawn(60) bibledelay = 0 - var/DBQuery/query = dbcon_old.NewQuery("SELECT * FROM library WHERE id=[sqlid]") + var/DBQuery/query = dbcon.NewQuery("SELECT * FROM library WHERE id=[sqlid]") query.Execute() while(query.NextRow()) diff --git a/code/world.dm b/code/world.dm index 9517f3ef..eaad49bb 100644 --- a/code/world.dm +++ b/code/world.dm @@ -342,7 +342,6 @@ var/world_topic_spam_protect_time = world.timeofday #define FAILED_DB_CONNECTION_CUTOFF 5 var/failed_db_connections = 0 -var/failed_old_db_connections = 0 /hook/startup/proc/connectDB() if(!setup_database_connection()) @@ -359,9 +358,9 @@ proc/setup_database_connection() if(!dbcon) dbcon = new() - var/user = sqlfdbklogin - var/pass = sqlfdbkpass - var/db = sqlfdbkdb + var/user = sqllogin + var/pass = sqlpass + var/db = sqldb var/address = sqladdress var/port = sqlport @@ -385,47 +384,4 @@ proc/establish_db_connection() else return 1 - -/hook/startup/proc/connectOldDB() - if(!setup_old_database_connection()) - world.log << "Your server failed to establish a connection with the SQL database." - else - world.log << "SQL database connection established." - return 1 - -//These two procs are for the old database, while it's being phased out. See the tgstation.sql file in the SQL folder for more information. -proc/setup_old_database_connection() - - if(failed_old_db_connections > FAILED_DB_CONNECTION_CUTOFF) //If it failed to establish a connection more than 5 times in a row, don't bother attempting to conenct anymore. - return 0 - - if(!dbcon_old) - dbcon_old = new() - - var/user = sqllogin - var/pass = sqlpass - var/db = sqldb - var/address = sqladdress - var/port = sqlport - - dbcon_old.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]") - . = dbcon_old.IsConnected() - if ( . ) - failed_old_db_connections = 0 //If this connection succeeded, reset the failed connections counter. - else - failed_old_db_connections++ //If it failed, increase the failed connections counter. - world.log << dbcon.ErrorMsg() - - return . - -//This proc ensures that the connection to the feedback database (global variable dbcon) is established -proc/establish_old_db_connection() - if(failed_old_db_connections > FAILED_DB_CONNECTION_CUTOFF) - return 0 - - if(!dbcon_old || !dbcon_old.IsConnected()) - return setup_old_database_connection() - else - return 1 - #undef FAILED_DB_CONNECTION_CUTOFF
AUTHORTITLECATEGORY