Better SQL prepared statements (#2474)

The system used to be of complexity O(n^2). Essentially two for loops running per every argument. Which ended up being surprisingly slow (there were instances where I saw the argument parser as using quite a lot of CPU time).

This replaces it with a more linear algorithm. It's somewhere near O(n) where n is the length of the unparsed query. Which is more stable and faaaster. This comes with two changes, however:

Parameters inside the query now have to be delimited from both sides with : (colons). The alternative to this would be to use something like $n or just assume that space marks the end of a marker. Only the former is workable, the latter would break a few queries already.
Arguments in the argument array no longer have to be prefixed by : (colons). So, while in the query you would write :thing:, you'd initialize the array of args as: list("thing" = somevar). It could be made to work without it, but eh, I think this is fine.
Argument validation is slightly weaker. What I mean by this is that with the old system, unused keys would result in an error. This is no longer a thing. Missing keys will still result in an error, however.
One more improvement: double delimiting removes an edge case where if key A partially covers key B, depending on the order, key A would mangle key B.
Updated and tested all queries that I could find. So this should be good.
This commit is contained in:
skull132
2017-05-29 21:17:41 +03:00
committed by GitHub
parent b88d6aaadb
commit a3ec0cf45d
36 changed files with 366 additions and 333 deletions

View File

@@ -106,8 +106,8 @@
return
var/DBQuery/check_query = dbcon.NewQuery("SELECT player_ckey, status FROM ss13_player_linking WHERE id = :id")
check_query.Execute(list(":id" = request_id))
var/DBQuery/check_query = dbcon.NewQuery("SELECT player_ckey, status FROM ss13_player_linking WHERE id = :id:")
check_query.Execute(list("id" = request_id))
if (!check_query.NextRow())
src << "<span class='warning'>No request found!</span>"
@@ -118,19 +118,19 @@
return
var/query_contents = ""
var/list/query_details = list(":new_status", ":id")
var/list/query_details = list("new_status", "id")
var/feedback_message = ""
switch (href_list["linkingaction"])
if ("accept")
query_contents = "UPDATE ss13_player_linking SET status = :new_status, updated_at = NOW() WHERE id = :id"
query_details[":new_status"] = "confirmed"
query_details[":id"] = request_id
query_contents = "UPDATE ss13_player_linking SET status = :new_status:, updated_at = NOW() WHERE id = :id:"
query_details["new_status"] = "confirmed"
query_details["id"] = request_id
feedback_message = "<font color='green'><b>Account successfully linked!</b></font>"
if ("deny")
query_contents = "UPDATE ss13_player_linking SET status = :new_status, deleted_at = NOW() WHERE id = :id"
query_details[":new_status"] = "rejected"
query_details[":id"] = request_id
query_contents = "UPDATE ss13_player_linking SET status = :new_status:, deleted_at = NOW() WHERE id = :id:"
query_details["new_status"] = "rejected"
query_details["id"] = request_id
feedback_message = "<font color='red'><b>Link request rejected!</b></font>"
else
@@ -516,9 +516,9 @@
return
var/list/requests = list()
var/list/query_details = list(":ckey" = ckey)
var/list/query_details = list("ckey" = ckey)
var/DBQuery/select_query = dbcon.NewQuery("SELECT id, forum_id, forum_username, datediff(Now(), created_at) as request_age FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey AND deleted_at IS NULL")
var/DBQuery/select_query = dbcon.NewQuery("SELECT id, forum_id, forum_username, datediff(Now(), created_at) as request_age FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey: AND deleted_at IS NULL")
select_query.Execute(query_details)
while (select_query.NextRow())
@@ -553,8 +553,8 @@
if (!dbcon.IsConnected())
return
var/DBQuery/select_query = dbcon.NewQuery("SELECT COUNT(*) AS request_count FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey AND deleted_at IS NULL")
select_query.Execute(list(":ckey" = ckey))
var/DBQuery/select_query = dbcon.NewQuery("SELECT COUNT(*) AS request_count FROM ss13_player_linking WHERE status = 'new' AND player_ckey = :ckey: AND deleted_at IS NULL")
select_query.Execute(list("ckey" = ckey))
if (select_query.NextRow())
if (text2num(select_query.item[1]) > 0)

View File

@@ -12,13 +12,13 @@
return list("ss13_characters" = list("vars" = list("be_special_role"), "args" = list("id")))
/datum/category_item/player_setup_item/antagonism/candidacy/gather_load_parameters()
return list(":id" = pref.current_character)
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/antagonism/candidacy/gather_save_query()
return list("ss13_characters" = list("be_special_role", "id" = 1, "ckey" = 1))
/datum/category_item/player_setup_item/antagonism/candidacy/gather_save_parameters()
return list(":be_special_role" = list2params(pref.be_special_role), ":id" = pref.current_character, ":ckey" = pref.client.ckey)
return list("be_special_role" = list2params(pref.be_special_role), "id" = pref.current_character, "ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/antagonism/candidacy/sanitize_character(var/sql_load = 0)
if (sql_load)

View File

@@ -17,14 +17,14 @@ var/global/list/uplink_locations = list("PDA", "Headset", "None")
"ss13_characters" = list("vars" = list("uplink_location" = "uplinklocation"), "args" = list("id")))
/datum/category_item/player_setup_item/antagonism/basic/gather_load_parameters()
return list(":char_id" = pref.current_character, ":id" = pref.current_character)
return list("char_id" = pref.current_character, "id" = pref.current_character)
/datum/category_item/player_setup_item/antagonism/basic/gather_save_query()
return list("ss13_characters_flavour" = list("records_exploit", "char_id" = 1),
"ss13_characters" = list("uplink_location", "id" = 1, "ckey" = 1))
/datum/category_item/player_setup_item/antagonism/basic/gather_save_parameters()
return list(":records_exploit" = pref.exploit_record, ":char_id" = pref.current_character, ":uplink_location" = pref.uplinklocation, ":id" = pref.current_character, ":ckey" = pref.client.ckey)
return list("records_exploit" = pref.exploit_record, "char_id" = pref.current_character, "uplink_location" = pref.uplinklocation, "id" = pref.current_character, "ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/antagonism/basic/sanitize_character()
pref.uplinklocation = sanitize_inlist(pref.uplinklocation, uplink_locations, initial(pref.uplinklocation))

View File

@@ -26,7 +26,7 @@
"args" = list("id")))
/datum/category_item/player_setup_item/general/basic/gather_load_parameters()
return list(":id" = pref.current_character)
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/general/basic/gather_save_query()
return list("ss13_characters" = list("name",
@@ -38,13 +38,13 @@
"ckey" = 1))
/datum/category_item/player_setup_item/general/basic/gather_save_parameters()
return list(":name" = pref.real_name,
":gender" = pref.gender,
":age" = pref.age,
":metadata" = pref.metadata,
":spawnpoint" = pref.spawnpoint,
":id" = pref.current_character,
":ckey" = pref.client.ckey)
return list("name" = pref.real_name,
"gender" = pref.gender,
"age" = pref.age,
"metadata" = pref.metadata,
"spawnpoint" = pref.spawnpoint,
"id" = pref.current_character,
"ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/general/basic/load_special()
pref.can_edit_name = 1
@@ -55,8 +55,8 @@
// Called /after/ loading and /before/ sanitization.
// So we have pref.current_character. It's just in text format.
var/DBQuery/query = dbcon.NewQuery("SELECT DATEDIFF(NOW(), created_at) AS DiffDate FROM ss13_characters WHERE id = :id")
query.Execute(list(":id" = text2num(pref.current_character)))
var/DBQuery/query = dbcon.NewQuery("SELECT DATEDIFF(NOW(), created_at) AS DiffDate FROM ss13_characters WHERE id = :id:")
query.Execute(list("id" = text2num(pref.current_character)))
if (query.NextRow())
if (text2num(query.item[1]) > 5)

View File

@@ -12,7 +12,7 @@
return list("ss13_characters" = list("vars" = list("language" = "alternate_languages"), "args" = list("id")))
/datum/category_item/player_setup_item/general/language/gather_load_parameters()
return list(":id" = pref.current_character)
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/general/language/gather_save_query()
return list("ss13_characters" = list("id" = 1,
@@ -20,9 +20,9 @@
"language"))
/datum/category_item/player_setup_item/general/language/gather_save_parameters()
return list(":language" = list2params(pref.alternate_languages),
":id" = pref.current_character,
":ckey" = pref.client.ckey)
return list("language" = list2params(pref.alternate_languages),
"id" = pref.current_character,
"ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/general/language/sanitize_character(var/sql_load = 0)
if (sql_load)

View File

@@ -64,7 +64,7 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
"args" = list("id")))
/datum/category_item/player_setup_item/general/body/gather_load_parameters()
return list(":id" = pref.current_character)
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/general/body/gather_save_query()
return list("ss13_characters" = list("species",
@@ -83,20 +83,20 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O
"ckey" = 1))
/datum/category_item/player_setup_item/general/body/gather_save_parameters()
return list(":species" = pref.species,
":hair_colour" = "#" + num2hex(pref.r_hair, 2) + num2hex(pref.g_hair, 2) + num2hex(pref.b_hair, 2),
":facial_colour" = "#" + num2hex(pref.r_facial, 2) + num2hex(pref.g_facial, 2) + num2hex(pref.b_facial, 2),
":skin_tone" = pref.s_tone,
":skin_colour" = "#" + num2hex(pref.r_skin, 2) + num2hex(pref.g_skin, 2) + num2hex(pref.b_skin, 2),
":hair_style" = pref.h_style,
":facial_style" = pref.f_style,
":eyes_colour" = "#" + num2hex(pref.r_eyes, 2) + num2hex(pref.g_eyes, 2) + num2hex(pref.b_eyes, 2),
":b_type" = pref.b_type,
":disabilities" = pref.disabilities,
":organs_data" = list2params(pref.organ_data),
":organs_robotic"= list2params(pref.rlimb_data),
":id" = pref.current_character,
":ckey" = pref.client.ckey)
return list("species" = pref.species,
"hair_colour" = "#" + num2hex(pref.r_hair, 2) + num2hex(pref.g_hair, 2) + num2hex(pref.b_hair, 2),
"facial_colour" = "#" + num2hex(pref.r_facial, 2) + num2hex(pref.g_facial, 2) + num2hex(pref.b_facial, 2),
"skin_tone" = pref.s_tone,
"skin_colour" = "#" + num2hex(pref.r_skin, 2) + num2hex(pref.g_skin, 2) + num2hex(pref.b_skin, 2),
"hair_style" = pref.h_style,
"facial_style" = pref.f_style,
"eyes_colour" = "#" + num2hex(pref.r_eyes, 2) + num2hex(pref.g_eyes, 2) + num2hex(pref.b_eyes, 2),
"b_type" = pref.b_type,
"disabilities" = pref.disabilities,
"organs_data" = list2params(pref.organ_data),
"organs_robotic"= list2params(pref.rlimb_data),
"id" = pref.current_character,
"ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/general/body/sanitize_character(var/sql_load = 0)
if(!pref.species || !(pref.species in playable_species))

View File

@@ -18,13 +18,13 @@
return list("ss13_characters" = list("vars" = list("underwear", "undershirt", "socks", "backbag"), "args" = list("id")))
/datum/category_item/player_setup_item/general/equipment/gather_load_parameters()
return list(":id" = pref.current_character)
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/general/equipment/gather_save_query()
return list("ss13_characters" = list("underwear", "undershirt", "socks", "backbag", "id" = 1, "ckey" = 1))
/datum/category_item/player_setup_item/general/equipment/gather_save_parameters()
return list(":underwear" = pref.underwear, ":undershirt" = pref.undershirt, ":socks" = pref.socks, ":backbag" = pref.backbag, ":id" = pref.current_character, ":ckey" = pref.client.ckey)
return list("underwear" = pref.underwear, "undershirt" = pref.undershirt, "socks" = pref.socks, "backbag" = pref.backbag, "id" = pref.current_character, "ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/general/equipment/sanitize_character(var/sql_load = 0)
if (sql_load)

View File

@@ -31,7 +31,7 @@
"ss13_characters" = list("vars" = list("home_system", "citizenship", "faction", "religion"), "args" = list("id")))
/datum/category_item/player_setup_item/general/background/gather_load_parameters()
return list(":id" = pref.current_character, ":char_id" = pref.current_character)
return list("id" = pref.current_character, "char_id" = pref.current_character)
/datum/category_item/player_setup_item/general/background/gather_save_query()
return list("ss13_characters_flavour" = list("records_employment",
@@ -41,16 +41,16 @@
"ss13_characters" = list("home_system", "citizenship", "faction", "religion", "id" = 1, "ckey" = 1))
/datum/category_item/player_setup_item/general/background/gather_save_parameters()
return list(":records_employment" = pref.gen_record,
":records_medical" = pref.med_record,
":records_security" = pref.sec_record,
":char_id" = pref.current_character,
":home_system" = pref.home_system,
":citizenship" = pref.citizenship,
":faction" = pref.faction,
":religion" = pref.religion,
":id" = pref.current_character,
":ckey" = pref.client.ckey)
return list("records_employment" = pref.gen_record,
"records_medical" = pref.med_record,
"records_security" = pref.sec_record,
"char_id" = pref.current_character,
"home_system" = pref.home_system,
"citizenship" = pref.citizenship,
"faction" = pref.faction,
"religion" = pref.religion,
"id" = pref.current_character,
"ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/general/background/sanitize_character()
if(!pref.home_system)

View File

@@ -59,7 +59,7 @@
return list("ss13_characters_flavour" = list("vars" = var_list, "args" = list("char_id")))
/datum/category_item/player_setup_item/general/flavor/gather_load_parameters()
return list(":char_id" = pref.current_character)
return list("char_id" = pref.current_character)
/datum/category_item/player_setup_item/general/flavor/gather_save_query()
var/list/var_list = list("flavour_general",
@@ -82,22 +82,22 @@
return list("ss13_characters_flavour" = var_list)
/datum/category_item/player_setup_item/general/flavor/gather_save_parameters()
var/list/var_list = list(":char_id" = pref.current_character,
":flavour_general" = pref.flavor_texts["general"],
":flavour_head" = pref.flavor_texts["head"],
":flavour_face" = pref.flavor_texts["face"],
":flavour_eyes" = pref.flavor_texts["eyes"],
":flavour_torso" = pref.flavor_texts["torso"],
":flavour_arms" = pref.flavor_texts["arms"],
":flavour_hands" = pref.flavor_texts["hands"],
":flavour_legs" = pref.flavor_texts["legs"],
":flavour_feet" = pref.flavor_texts["feet"],
":robot_default" = pref.flavour_texts_robot["default"],
":signature_font" = pref.signfont,
":signature" = pref.signature)
var/list/var_list = list("char_id" = pref.current_character,
"flavour_general" = pref.flavor_texts["general"],
"flavour_head" = pref.flavor_texts["head"],
"flavour_face" = pref.flavor_texts["face"],
"flavour_eyes" = pref.flavor_texts["eyes"],
"flavour_torso" = pref.flavor_texts["torso"],
"flavour_arms" = pref.flavor_texts["arms"],
"flavour_hands" = pref.flavor_texts["hands"],
"flavour_legs" = pref.flavor_texts["legs"],
"flavour_feet" = pref.flavor_texts["feet"],
"robot_default" = pref.flavour_texts_robot["default"],
"signature" = pref.signature,
"signature_font" = pref.signfont)
for (var/module in robot_module_types)
var_list[":robot_[module]"] += pref.flavour_texts_robot[module]
var_list["robot_[module]"] += pref.flavour_texts_robot[module]
return var_list

View File

@@ -18,13 +18,13 @@
return list("ss13_player_preferences" = list("vars" = list("UI_style", "UI_style_color", "UI_style_alpha", "ooccolor"), "args" = list("ckey")))
/datum/category_item/player_setup_item/player_global/ui/gather_load_parameters()
return list(":ckey" = pref.client.ckey)
return list("ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/player_global/ui/gather_save_query()
return list("ss13_player_preferences" = list("UI_style", "UI_style_color", "UI_style_alpha", "ooccolor", "ckey" = 1))
/datum/category_item/player_setup_item/player_global/ui/gather_save_parameters()
return list(":ckey" = pref.client.ckey, ":UI_style_alpha" = pref.UI_style_alpha, ":UI_style_color" = pref.UI_style_color, ":UI_style" = pref.UI_style, ":ooccolor" = pref.ooccolor)
return list("ckey" = pref.client.ckey, "UI_style_alpha" = pref.UI_style_alpha, "UI_style_color" = pref.UI_style_color, "UI_style" = pref.UI_style, "ooccolor" = pref.ooccolor)
/datum/category_item/player_setup_item/player_global/ui/sanitize_preferences()
pref.UI_style = sanitize_inlist(pref.UI_style, all_ui_styles, initial(pref.UI_style))

View File

@@ -26,21 +26,21 @@
return list("ss13_player_preferences" = list("vars" = list("lastchangelog", "current_character", "toggles", "asfx_togs", "lastmotd" = "motd_hash", "lastmemo" = "memo_hash"), "args" = list("ckey")))
/datum/category_item/player_setup_item/player_global/settings/gather_load_parameters()
return list(":ckey" = pref.client.ckey)
return list("ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/player_global/settings/gather_save_query()
return list("ss13_player_preferences" = list("lastchangelog", "current_character", "toggles", "asfx_togs", "lastmotd", "lastmemo", "ckey" = 1, "parallax_toggles", "parallax_speed"))
/datum/category_item/player_setup_item/player_global/settings/gather_save_parameters()
return list(":ckey" = pref.client.ckey,
":lastchangelog" = pref.lastchangelog,
":current_character" = pref.current_character,
":toggles" = pref.toggles,
":asfx_togs" = pref.asfx_togs,
":lastmotd" = pref.motd_hash,
":lastmemo" = pref.memo_hash,
":parallax_toggles" = pref.parallax_togs,
":parallax_speed" = pref.parallax_speed)
return list("ckey" = pref.client.ckey,
"lastchangelog" = pref.lastchangelog,
"current_character" = pref.current_character,
"toggles" = pref.toggles,
"asfx_togs" = pref.asfx_togs,
"lastmotd" = pref.motd_hash,
"lastmemo" = pref.memo_hash,
"parallax_toggles" = pref.parallax_togs,
"parallax_speed" = pref.parallax_speed)
/datum/category_item/player_setup_item/player_global/settings/sanitize_preferences(var/sql_load = 0)
if (sql_load)

View File

@@ -12,13 +12,13 @@
return list("ss13_player_preferences" = list("vars" = list("language_prefixes"), "args" = list("ckey")))
/datum/category_item/player_setup_item/player_global/language/gather_load_parameters()
return list(":ckey" = pref.client.ckey)
return list("ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/player_global/language/gather_save_query()
return list("ss13_player_preferences" = list("language_prefixes", "ckey" = 1))
/datum/category_item/player_setup_item/player_global/language/gather_save_parameters()
return list(":ckey" = pref.client.ckey, ":language_prefixes" = list2params(pref.language_prefixes))
return list("ckey" = pref.client.ckey, "language_prefixes" = list2params(pref.language_prefixes))
/datum/category_item/player_setup_item/player_global/language/sanitize_preferences(var/sql_load = 0)
if (sql_load && pref.language_prefixes)

View File

@@ -31,7 +31,7 @@
return list("ss13_player_pai" = list("vars" = list("name" = "pai/name", "description" = "pai/description", "role" = "pai/role", "comments" = "pai/comments"), "args" = list("ckey")))
/datum/category_item/player_setup_item/player_global/pai/gather_load_parameters()
return list(":ckey" = pref.client.ckey)
return list("ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/player_global/pai/gather_save_query()
return list("ss13_player_pai" = list("name", "description", "role", "comments", "ckey" = 1))
@@ -40,7 +40,7 @@
if (!candidate)
return list()
return list(":ckey" = pref.client.ckey, ":name" = candidate.name, ":description" = candidate.description, ":role" = candidate.role, ":comments" = candidate.comments)
return list("ckey" = pref.client.ckey, "name" = candidate.name, "description" = candidate.description, "role" = candidate.role, "comments" = candidate.comments)
/datum/category_item/player_setup_item/player_global/pai/sanitize_preferences(var/sql_load = 0)
if (sql_load && candidate && pref.pai.len)

View File

@@ -44,7 +44,7 @@ var/list/gear_datums = list()
S["gear"] << pref.gear
/datum/category_item/player_setup_item/loadout/gather_load_parameters()
return list(":id" = pref.current_character)
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/loadout/gather_load_query()
return list("ss13_characters" = list("vars" = list("gear"), "args" = list("id")))
@@ -53,7 +53,7 @@ var/list/gear_datums = list()
return list("ss13_characters" = list("gear", "id" = 1, "ckey" = 1))
/datum/category_item/player_setup_item/loadout/gather_save_parameters()
return list(":gear" = json_encode(pref.gear), ":id" = pref.current_character, ":ckey" = pref.client.ckey)
return list("gear" = json_encode(pref.gear), "id" = pref.current_character, "ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/loadout/proc/valid_gear_choices(var/max_cost)
. = list()

View File

@@ -37,7 +37,7 @@
return list("ss13_characters" = list("vars" = list("jobs" = "unsanitized_jobs", "alternate_option", "alternate_titles" = "player_alt_titles"), "args" = list("id")))
/datum/category_item/player_setup_item/occupation/gather_load_parameters()
return list(":id" = pref.current_character)
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/occupation/gather_save_query()
return list("ss13_characters" = list("jobs", "alternate_option", "alternate_titles", "id" = 1, "ckey" = 1))
@@ -53,7 +53,7 @@
"job_engsec_med" = pref.job_engsec_med,
"job_engsec_low" = pref.job_engsec_low)
return list(":jobs" = list2params(compiled_jobs), ":alternate_option" = pref.alternate_option, ":alternate_titles" = list2params(pref.player_alt_titles), ":id" = pref.current_character, ":ckey" = pref.client.ckey)
return list("jobs" = list2params(compiled_jobs), "alternate_option" = pref.alternate_option, "alternate_titles" = list2params(pref.player_alt_titles), "id" = pref.current_character, "ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/occupation/sanitize_character(var/sql_load = 0)
if (sql_load)

View File

@@ -19,11 +19,11 @@
JOIN ss13_characters chr ON act_chr.char_id = chr.id
JOIN ss13_ccia_actions act ON act_chr.action_id = act.id
WHERE
act_chr.char_id = ':char_id' AND
act_chr.char_id = :char_id: AND
(act.expires_at IS NULL OR act.expires_at >= CURRENT_DATE()) AND
act.deleted_at IS NULL;
"})
if (!ccia_action_query.Execute(list(":char_id" = pref.current_character)))
if (!ccia_action_query.Execute(list("char_id" = pref.current_character)))
error("Error CCIA Actions for character #[pref.current_character]. SQL error message: '[ccia_action_query.ErrorMsg()]'.")
while(ccia_action_query.NextRow())
@@ -42,9 +42,9 @@
id, char_id, UID, datetime, notes, charges, evidence, arbiters, brig_sentence, fine, felony
FROM ss13_character_incidents
WHERE
char_id = ':char_id' AND deleted_at IS NULL
char_id = :char_id: AND deleted_at IS NULL
"})
char_infraction_query.Execute(list(":char_id" = pref.current_character))
char_infraction_query.Execute(list("char_id" = pref.current_character))
while(char_infraction_query.NextRow())
var/datum/char_infraction/infraction = new()

View File

@@ -70,8 +70,7 @@
var/list/arg_names = tables[table]["args"]
count = arg_names.len
for (i = 1, i <= count, i++)
query += "[arg_names[i]] = :[arg_names[i]]"
arg_names[i] = ":[arg_names[i]]"
query += "[arg_names[i]] = :[arg_names[i]]:"
if (i != count)
query += " AND "
@@ -96,7 +95,7 @@
for (var/query_text in query_cache[type])
var/DBQuery/query = dbcon.NewQuery(query_text)
query.Execute(arg_list, 1)
query.Execute(arg_list)
if (query.ErrorMsg())
error("SQL CHARACTER LOAD: SQL query error: [query.ErrorMsg()]")
log_debug("SQL CHARACTER LOAD: SQL query error: [query.ErrorMsg()]")
@@ -180,7 +179,7 @@
// Process the args.
var/list/arg_names = list()
for (var/variable in var_names)
arg_names += ":[variable]"
arg_names += ":[variable]:"
query += "[jointext(arg_names, ", ")]) ON DUPLICATE KEY UPDATE"
@@ -215,7 +214,7 @@
var/datum/category_collection/player_setup_collection/cc = collection
for (var/query_text in query_cache[type])
var/DBQuery/query = dbcon.NewQuery(query_text)
query.Execute(arg_list, 1)
query.Execute(arg_list)
if (query.ErrorMsg())
error("SQL CHARACTER SAVE: SQL query error: [query.ErrorMsg()]")

View File

@@ -16,13 +16,13 @@
return list("ss13_characters" = list("vars" = list("skills", "skill_specialization"), "args" = list("id")))
/datum/category_item/player_setup_item/skills/gather_load_parameters()
return list(":id" = pref.current_character)
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/skills/gather_save_query()
return list("ss13_characters" = list("skills", "skill_specialization", "id" = 1, "ckey" = 1))
/datum/category_item/player_setup_item/skills/gather_save_parameters()
return list(":skills" = list2params(pref.skills), ":skill_specialization" = pref.skill_specialization, ":id" = pref.current_character, ":ckey" = pref.client.ckey)
return list("skills" = list2params(pref.skills), "skill_specialization" = pref.skill_specialization, "id" = pref.current_character, "ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/skills/sanitize_character(var/sql_load = 0)
if (SKILLS == null)

View File

@@ -415,8 +415,8 @@ datum/preferences
if(!dbcon.IsConnected())
return open_load_dialog_file(user)
var/DBQuery/query = dbcon.NewQuery("SELECT id, name FROM ss13_characters WHERE ckey = :ckey AND deleted_at IS NULL ORDER BY id ASC")
query.Execute(list(":ckey" = user.client.ckey))
var/DBQuery/query = dbcon.NewQuery("SELECT id, name FROM ss13_characters WHERE ckey = :ckey: AND deleted_at IS NULL ORDER BY id ASC")
query.Execute(list("ckey" = user.client.ckey))
dat += "<b>Select a character slot to load</b><hr>"
var/name
@@ -471,8 +471,8 @@ datum/preferences
if (!config.sql_saves || !config.sql_stats || !establish_db_connection(dbcon) || !H)
return
var/DBQuery/query = dbcon.NewQuery("INSERT INTO ss13_characters_log (char_id, game_id, datetime, job_name, special_role) VALUES (:char_id, :game_id, NOW(), :job, :special_role)")
query.Execute(list(":char_id" = current_character, ":game_id" = game_id, ":job" = H.mind.assigned_role, ":special_role" = H.mind.special_role))
var/DBQuery/query = dbcon.NewQuery("INSERT INTO ss13_characters_log (char_id, game_id, datetime, job_name, special_role) VALUES (:char_id:, :game_id:, NOW(), :job:, :special_role:)")
query.Execute(list("char_id" = current_character, "game_id" = game_id, "job" = H.mind.assigned_role, "special_role" = H.mind.special_role))
// Turned into a proc so we could reuse it for SQL shenanigans.
/datum/preferences/proc/new_setup(var/re_initialize = 0)
@@ -570,8 +570,8 @@ datum/preferences
C << "<span class='notice'>Unable to establish database connection.</span>"
return
var/DBQuery/query = dbcon.NewQuery("UPDATE ss13_characters SET deleted_at = NOW() WHERE id = :char_id")
query.Execute(list(":char_id" = current_character))
var/DBQuery/query = dbcon.NewQuery("UPDATE ss13_characters SET deleted_at = NOW() WHERE id = :char_id:")
query.Execute(list("char_id" = current_character))
// Create a new character.
new_setup(1)

View File

@@ -165,8 +165,8 @@
error("Error initiatlizing database connection while counting CCIA actions.")
return null
var/DBQuery/prep_query = dbcon.NewQuery("SELECT id FROM ss13_characters WHERE ckey = :ckey")
prep_query.Execute(list(":ckey" = user.ckey))
var/DBQuery/prep_query = dbcon.NewQuery("SELECT id FROM ss13_characters WHERE ckey = :ckey:")
prep_query.Execute(list("ckey" = user.ckey))
var/list/chars = list()
while (prep_query.NextRow())
@@ -181,10 +181,10 @@
JOIN ss13_characters chr ON act_chr.char_id = chr.id
JOIN ss13_ccia_actions act ON act_chr.action_id = act.id
WHERE
act_chr.char_id IN :char_id AND
act_chr.char_id IN :char_id: AND
(act.expires_at IS NULL OR act.expires_at >= CURRENT_DATE()) AND
act.deleted_at IS NULL;"})
query.Execute(list(":char_id" = chars))
query.Execute(list("char_id" = chars))
if (query.NextRow())
var/action_count = text2num(query.item[1])