From 627a3fe38404342ef5558b6c620ef4d93b566cca Mon Sep 17 00:00:00 2001 From: skull132 Date: Fri, 8 Jan 2016 00:53:15 +0200 Subject: [PATCH 1/3] Consistent SQL ErrorMsg() logging & parseArguments Fix Adds an automatic check for DBQuery.ErrorMsg() every time a DBQuery.Execute() proc is called. This makes hunting down unknown DB errors way easier. Also makes working with database functions less frustrating. Fixes my dungoof with the DBQuery.parseArguments() function as well. The string is now properly updated in the for() loop. --- code/defines/procs/dbcore.dm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/code/defines/procs/dbcore.dm b/code/defines/procs/dbcore.dm index 2f4d419e..e27a7ce2 100644 --- a/code/defines/procs/dbcore.dm +++ b/code/defines/procs/dbcore.dm @@ -117,7 +117,12 @@ DBQuery/proc/Execute(var/list/argument_list = null, var/pass_not_found = 0, sql_ if (argument_list) sql_query = parseArguments(sql_query, argument_list, pass_not_found) - return _dm_db_execute(_db_query, sql_query, db_connection._db_con, cursor_handler, null) + var/return_value = _dm_db_execute(_db_query, sql_query, db_connection._db_con, cursor_handler, null) + + if (ErrorMsg()) + log_debug("SQL Error: [ErrorMsg()]") + + return return_value DBQuery/proc/NextRow() return _dm_db_next_row(_db_query,item,conversions) @@ -176,13 +181,15 @@ DBQuery/proc/SetConversion(column,conversion) */ DBQuery/proc/parseArguments(var/query_to_parse = null, var/list/argument_list, var/pass_not_found = 0) if (!query_to_parse || !argument_list || !argument_list.len) + log_debug("SQL Error: parseArguments() called with an empty query_to_parse or argument_list.") return 0 for (var/placeholder in argument_list) - if (!findtextEx(sql, placeholder)) + if (!findtextEx(query_to_parse, placeholder)) if (pass_not_found) continue else + log_debug("SQL Error: parseArguments() failed to find placeholder. Placeholder value: [placeholder].") return 0 var/argument = argument_list[placeholder] @@ -194,9 +201,10 @@ DBQuery/proc/parseArguments(var/query_to_parse = null, var/list/argument_list, v else if (isnum(argument)) argument = "'[argument]'" else + log_debug("SQL Error: parseArguments() failed to identify argument type. Placeholder value: [placeholder].") return 0 - query_to_parse = replacetextEx(sql, placeholder, argument) + query_to_parse = replacetextEx(query_to_parse, placeholder, argument) return query_to_parse From a15019183c088acd606d99ac9fabd38c53562168 Mon Sep 17 00:00:00 2001 From: skull132 Date: Fri, 8 Jan 2016 12:18:13 +0200 Subject: [PATCH 2/3] Logging Species Played Onto Feedback Database --- code/game/gamemodes/game_mode.dm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/code/game/gamemodes/game_mode.dm b/code/game/gamemodes/game_mode.dm index a50acff2..7864827e 100644 --- a/code/game/gamemodes/game_mode.dm +++ b/code/game/gamemodes/game_mode.dm @@ -148,6 +148,7 @@ Implants; var/surviving_total = 0 var/ghosts = 0 var/escaped_humans = 0 + var/species_stats = list("Humans" = 0, "Unathi" = 0, "Tajaran" = 0, "Skrell" = 0, "Vaurca" = 0, "IPC" = 0, "Diona" = 0) var/escaped_total = 0 var/escaped_on_pod_1 = 0 var/escaped_on_pod_2 = 0 @@ -165,6 +166,23 @@ Implants; surviving_humans++ if(M.loc && M.loc.loc && M.loc.loc.type in escape_locations) escaped_humans++ + var/mob/living/carbon/human/H = M + if (H.species) + switch (H.species.name) + if ("Human") + species_stats["Human"]++ + if ("Unathi") + species_stats["Unathi"]++ + if ("Tajaran") + species_stats["Tajaran"]++ + if ("Skrell") + species_stats["Skrell"]++ + if ("Vaurca") + species_stats["Vaurca"]++ + if ("Machine") + species_stats["IPC"]++ + if ("Diona") + species_stats["Diona"]++ if(!M.stat) surviving_total++ if(M.loc && M.loc.loc && M.loc.loc.type in escape_locations) @@ -191,6 +209,12 @@ Implants; feedback_set("round_end_ghosts",ghosts) if(surviving_humans > 0) feedback_set("survived_human",surviving_humans) + + var/species_stats_string = "" + for (var/species_name in species_stats) + species_stats_string += "[species_name]: [species_stats[species_name]], " + + feedback_set("species_statistics", species_stats_string) if(surviving_total > 0) feedback_set("survived_total",surviving_total) if(escaped_humans > 0) From 57c652573a7aab189f21945b174cac8fb18e2a16 Mon Sep 17 00:00:00 2001 From: skull132 Date: Fri, 8 Jan 2016 13:37:08 +0200 Subject: [PATCH 3/3] cycle_db_connection() Proc Adds a proc to force a db disconnect, and to re-establish it. As it stands, can only be called through advanced proc-call. --- code/world.dm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/code/world.dm b/code/world.dm index e0a54dc7..ccbd7673 100644 --- a/code/world.dm +++ b/code/world.dm @@ -423,4 +423,15 @@ proc/establish_db_connection() else return 1 +//This proc disconnects the database forcefully, and then establishes connection again. +proc/cycle_db_connection() + if (!dbcon) + return 0 + + log_debug("Cycling database connection.") + dbcon.Disconnect() + + sleep(5) + setup_database_connection() + #undef FAILED_DB_CONNECTION_CUTOFF