<commit_before>#define FAILED_DB_CONNECTION_CUTOFF 5
#define DM_DEFAULT_CURSOR 0

SUBSYSTEM_DEF(dbcore)
	name = "Database"
	flags = SS_NO_FIRE
	init_order = INIT_ORDER_DBCORE

	var/schema_mismatch = 0
	var/db_minor = 0
	var/db_major = 0

	var/_db_con// This variable contains a reference to the actual database connection.
	var/failed_connections = 0

/datum/controller/subsystem/dbcore/PreInit()
	if(!_db_con)
		_db_con = _dm_db_new_con()

/datum/controller/subsystem/dbcore/Initialize()
	//We send warnings to the admins during subsystem init, as the clients will be New'd and messages
	//will queue properly with goonchat
	switch(schema_mismatch)
		if(1)
			message_admins("Database schema ([db_major].[db_minor]) doesn't match the latest schema version ([DB_MAJOR_VERSION].[DB_MINOR_VERSION]), this may lead to undefined behaviour or errors")
		if(2)
			message_admins("Could not get schema version from database")

	
/datum/controller/subsystem/dbcore/Recover()
	_db_con = SSdbcore._db_con

/datum/controller/subsystem/dbcore/Shutdown()
	//This is as close as we can get to the true round end before Disconnect() without changing where it's called, defeating the reason this is a subsystem
	if(SSdbcore.Connect())
		var/sql_station_name = sanitizeSQL(station_name())
		var/datum/DBQuery/query_round_end = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET end_datetime = Now(), game_mode_result = '[SSticker.mode_result]', end_state = '[SSticker.end_state]', station_name = '[sql_station_name]' WHERE id = [GLOB.round_id]")
		query_round_end.Execute()
	if(IsConnected())
		Disconnect()

//nu
/datum/controller/subsystem/dbcore/can_vv_get(var_name)
	return var_name != "_db_con" && ..()

/datum/controller/subsystem/dbcore/vv_edit_var(var_name, var_value)
	if(var_name == "_db_con")
		return FALSE
	return ..()

/datum/controller/subsystem/dbcore/proc/Connect()
	if(IsConnected())
		return TRUE
<commit_msg>Revert "Revert "Fix sql injection""<commit_after>#define FAILED_DB_CONNECTION_CUTOFF 5
#define DM_DEFAULT_CURSOR 0

SUBSYSTEM_DEF(dbcore)
	name = "Database"
	flags = SS_NO_FIRE
	init_order = INIT_ORDER_DBCORE

	var/schema_mismatch = 0
	var/db_minor = 0
	var/db_major = 0

	var/_db_con// This variable contains a reference to the actual database connection.
	var/failed_connections = 0

/datum/controller/subsystem/dbcore/PreInit()
	if(!_db_con)
		_db_con = _dm_db_new_con()

/datum/controller/subsystem/dbcore/Initialize()
	//We send warnings to the admins during subsystem init, as the clients will be New'd and messages
	//will queue properly with goonchat
	switch(schema_mismatch)
		if(1)
			message_admins("Database schema ([db_major].[db_minor]) doesn't match the latest schema version ([DB_MAJOR_VERSION].[DB_MINOR_VERSION]), this may lead to undefined behaviour or errors")
		if(2)
			message_admins("Could not get schema version from database")

	
/datum/controller/subsystem/dbcore/Recover()
	_db_con = SSdbcore._db_con

/datum/controller/subsystem/dbcore/Shutdown()
	//This is as close as we can get to the true round end before Disconnect() without changing where it's called, defeating the reason this is a subsystem
	if(SSdbcore.Connect())
		var/sql_station_name = sanitizeSQL(station_name())
		var/datum/DBQuery/query_round_end = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET end_datetime = Now(), game_mode_result = '[sanitizeSQL(SSticker.mode_result)]', end_state = '[sanitizeSQL(SSticker.end_state)]', station_name = '[sql_station_name]' WHERE id = [GLOB.round_id]")
		query_round_end.Execute()
	if(IsConnected())
		Disconnect()

//nu
/datum/controller/subsystem/dbcore/can_vv_get(var_name)
	return var_name != "_db_con" && ..()

/datum/controller/subsystem/dbcore/vv_edit_var(var_name, var_value)
	if(var_name == "_db_con")
		return FALSE
	return ..()

/datum/controller/subsystem/dbcore/proc/Connect()
	if(IsConnected())
		return TRUE

{'fraction_non_alphanumeric': 0.1116829644879053, 'fraction_numerical': 0.004117344312918168, 'mean_word_length': 5.403624382207578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '956963', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1341, 'n_words': 314}