diff --git a/code/controllers/subsystems/cargo.dm b/code/controllers/subsystems/cargo.dm index 690cff3b6db..f94e6769957 100644 --- a/code/controllers/subsystems/cargo.dm +++ b/code/controllers/subsystems/cargo.dm @@ -618,25 +618,17 @@ SUBSYSTEM_DEF(cargo) return 1 /// Dumps the cargo orders to the database when the round ends. -/datum/controller/subsystem/cargo/proc/dump_orders() +/datum/controller/subsystem/cargo/Shutdown() if(dumped_orders) log_subsystem_cargo("SQL: Orders already dumped. Cargo data dump has been aborted.") return - if(!establish_db_connection(GLOB.dbcon)) + if(!SSdbcore.Connect()) log_subsystem_cargo("SQL: Unable to connect to SQL database. Cargo data dump has been aborted.") return dumped_orders = TRUE // Loop through all the orders and dump them all. - var/DBQuery/dump_query = GLOB.dbcon.NewQuery("INSERT INTO `ss13_cargo_orderlog` (`game_id`, `order_id`, `status`, `price`, `ordered_by_id`, `ordered_by`, `authorized_by_id`, `authorized_by`, `received_by_id`, `received_by`, `paid_by_id`, `paid_by`, `time_submitted`, `time_approved`, `time_shipped`, `time_delivered`, `time_paid`, `reason`) \ - VALUES (:game_id:, :order_id:, :status:, :price:, :ordered_by_id:, :ordered_by:, :authorized_by_id:, :authorized_by:, :received_by_id:, :received_by:, :paid_by_id:, :paid_by:, :time_submitted:, :time_approved:, :time_shipped:, :time_delivered:, :time_paid:, :reason:)") - - var/DBQuery/dump_item_query = GLOB.dbcon.NewQuery("INSERT INTO `ss13_cargo_item_orderlog` (`cargo_orderlog_id`, `item_name`, `amount`) \ - VALUES (:cargo_orderlog_id:, :item_name:, :amount:)") - - var/DBQuery/log_id = GLOB.dbcon.NewQuery("SELECT LAST_INSERT_ID() AS log_id") - for(var/datum/cargo_order/co in all_orders) // Iterate over the items in the order and build the a list with the item count. var/list/itemcount = list() @@ -649,7 +641,9 @@ SUBSYSTEM_DEF(cargo) itemnames["[coi.ci.id]"] = coi.ci.name - if(!dump_query.Execute(list( + var/datum/db_query/dump_query = SSdbcore.NewQuery("INSERT INTO `ss13_cargo_orderlog` (`game_id`, `order_id`, `status`, `price`, `ordered_by_id`, `ordered_by`, `authorized_by_id`, `authorized_by`, `received_by_id`, `received_by`, `paid_by_id`, `paid_by`, `time_submitted`, `time_approved`, `time_shipped`, `time_delivered`, `time_paid`, `reason`) \ + VALUES (:game_id, :order_id, :status, :price, :ordered_by_id, :ordered_by, :authorized_by_id, :authorized_by, :received_by_id, :received_by, :paid_by_id, :paid_by, :time_submitted, :time_approved, :time_shipped, :time_delivered, :time_paid, :reason)", + list( "game_id"=GLOB.round_id, "order_id"=co.order_id, "status"=co.status, @@ -668,30 +662,25 @@ SUBSYSTEM_DEF(cargo) "time_delivered"=co.time_delivered, "time_paid"=co.time_paid, "reason"=co.reason - ))) + ), TRUE) + + if(!dump_query.Execute()) log_subsystem_cargo("SQL: Could not write order to database. Cargo data dump has been aborted.") continue - // Run the query to get the inserted ID. - log_id.Execute() - - var/db_log_id = null - if(log_id.NextRow()) - db_log_id = text2num(log_id.item[1]) - - if(db_log_id) + if(dump_query.last_insert_id) for(var/item_id in itemcount) - if(!dump_item_query.Execute(list( - "cargo_orderlog_id" = db_log_id, + var/datum/db_query/dump_item_query = SSdbcore.NewQuery("INSERT INTO `ss13_cargo_item_orderlog` (`cargo_orderlog_id`, `item_name`, `amount`) \ + VALUES (:cargo_orderlog_id, :item_name, :amount)", + list( + "cargo_orderlog_id" = dump_query.last_insert_id, "item_name"= itemnames[item_id], "amount" = itemcount[item_id] - ))) + ), + TRUE) + if(!dump_item_query.Execute()) log_subsystem_cargo("SQL: Cound not write details of a cargo order.") + qdel(dump_item_query) continue - CHECK_TICK - - log_subsystem_cargo("SQL: Saved cargo order log to database.") - - -/hook/roundend/proc/dump_cargoorders() - SScargo.dump_orders() + qdel(dump_query) + log_subsystem_cargo("SQL: Saved cargo order log to database.") diff --git a/html/changelogs/arrow768-dbcore-cargo.yml b/html/changelogs/arrow768-dbcore-cargo.yml new file mode 100644 index 00000000000..3f9c13d6fa9 --- /dev/null +++ b/html/changelogs/arrow768-dbcore-cargo.yml @@ -0,0 +1,58 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: arrow768 + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - server: "Changed the Cargo Subsystem to use the new DBCore"