mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
Adds BSQL (#38323)
* Add BSQL library v1.1.1.0 * Modify dbcore to use BSQL * Add missing QDEL_NULL for connectOperation * Moves BSQL_Shutdown() call to dbcore shutdown * Fix passing the wrong argument to DBQuery/New() * Darn it @Jordie0608. Fixes db calls without Connect check No seriously please make sure I'm not breaking anything * Queries with a null connection won't runtime * Fix quoting * Fix mistake * Update BSQL to v1.1.2.0 * Update BSQL DMAPI to v1.0.1.0 * Fix connection instatiation * Does the smart thing in regards to quoting * Fix braces * Update BSQL to 1.2.0.0. DMAPI to 1.1.0.0 * Execute/NextRow/MassInsert now have async parameter * Build BSQL for tests * Add missing apt source * Def still need gcc-multilib * Wut * Revert "Wut" This reverts commit d7c98a9a6b27f6db03e9f5cc534650d59d018048. * Try this then * Could it really be that simple? * Literally running out of ideas here * Update BSQL to v1.2.1.0 DMAPI to v1.1.1.0 * Update BSQL travis version * Nothing about this makes sense tbqhwyfam * Whoo boy * No idea why this isn't working tbh * Absolute madness * Ahhhhhhhhhhhhh * *deep breath* * "though yet again i was frustrated by failure" * Add BSQL to Dockerfile * Pass through MassInsert async param * BSQL to v1.3.0.0 DMAPI to 1.2.0.0 * Add timeout support * Wait, something's fucky * Wtf is this meme? * Just get good lmao * Just stop being shit lol * Stupid verbose logging * Remove verbosity * Good god * BSQL to v1.3.0.1 DMAPI to v1.2.0.1 * BSQL to v1.3.0.2 * Update BSQL travis version * Update BSQL docker version * Didn't mean to change that * Strip connection information from debug logs and make it configgable * Move this to where CONFIG_GET is defined
This commit is contained in:
7
code/modules/bsql/LICENSE
Normal file
7
code/modules/bsql/LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright 2018 Jordan Brown
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
66
code/modules/bsql/core/connection.dm
Normal file
66
code/modules/bsql/core/connection.dm
Normal file
@@ -0,0 +1,66 @@
|
||||
/datum/BSQL_Connection
|
||||
var/id
|
||||
var/connection_type
|
||||
|
||||
BSQL_PROTECT_DATUM(/datum/BSQL_Connection)
|
||||
|
||||
/datum/BSQL_Connection/New(connection_type, asyncTimeout, blockingTimeout)
|
||||
if(asyncTimeout == null)
|
||||
asyncTimeout = BSQL_DEFAULT_TIMEOUT
|
||||
if(blockingTimeout == null)
|
||||
blockingTimeout = asyncTimeout
|
||||
|
||||
src.connection_type = connection_type
|
||||
|
||||
world._BSQL_InitCheck(src)
|
||||
|
||||
var/error = world._BSQL_Internal_Call("CreateConnection", connection_type, "[asyncTimeout]", "[blockingTimeout]")
|
||||
if(error)
|
||||
BSQL_ERROR(error)
|
||||
return
|
||||
|
||||
id = world._BSQL_Internal_Call("GetConnection")
|
||||
if(!id)
|
||||
BSQL_ERROR("BSQL library failed to provide connect operation for connection id [id]([connection_type])!")
|
||||
|
||||
BSQL_DEL_PROC(/datum/BSQL_Connection)
|
||||
var/error
|
||||
if(id)
|
||||
error = world._BSQL_Internal_Call("ReleaseConnection", id)
|
||||
. = ..()
|
||||
if(error)
|
||||
BSQL_ERROR(error)
|
||||
|
||||
/datum/BSQL_Connection/BeginConnect(ipaddress, port, username, password, database)
|
||||
var/error = world._BSQL_Internal_Call("OpenConnection", id, ipaddress, "[port]", username, password, database)
|
||||
if(error)
|
||||
BSQL_ERROR(error)
|
||||
return
|
||||
|
||||
var/op_id = world._BSQL_Internal_Call("GetOperation")
|
||||
if(!op_id)
|
||||
BSQL_ERROR("Library failed to provide connect operation for connection id [id]([connection_type])!")
|
||||
return
|
||||
|
||||
return new /datum/BSQL_Operation(src, op_id)
|
||||
|
||||
|
||||
/datum/BSQL_Connection/BeginQuery(query)
|
||||
var/error = world._BSQL_Internal_Call("NewQuery", id, query)
|
||||
if(error)
|
||||
BSQL_ERROR(error)
|
||||
return
|
||||
|
||||
var/op_id = world._BSQL_Internal_Call("GetOperation")
|
||||
if(!op_id)
|
||||
BSQL_ERROR("Library failed to provide query operation for connection id [id]([connection_type])!")
|
||||
return
|
||||
|
||||
return new /datum/BSQL_Operation/Query(src, op_id)
|
||||
|
||||
/datum/BSQL_Connection/Quote(str)
|
||||
if(!str)
|
||||
return null;
|
||||
. = world._BSQL_Internal_Call("QuoteString", id, "[str]")
|
||||
if(!.)
|
||||
BSQL_ERROR("Library failed to provide quote for [str]!")
|
||||
37
code/modules/bsql/core/library.dm
Normal file
37
code/modules/bsql/core/library.dm
Normal file
@@ -0,0 +1,37 @@
|
||||
/world/proc/_BSQL_Internal_Call(func, ...)
|
||||
var/list/call_args = args.Copy(2)
|
||||
BSQL_Debug("[.....]: [args[1]]([call_args.Join(", ")])")
|
||||
. = call(_BSQL_Library_Path(), func)(arglist(call_args))
|
||||
BSQL_Debug("Result: [. == null ? "NULL" : "\"[.]\""]")
|
||||
|
||||
/world/proc/_BSQL_Library_Path()
|
||||
return system_type == MS_WINDOWS ? "BSQL.dll" : "libBSQL.so"
|
||||
|
||||
/world/proc/_BSQL_InitCheck(datum/BSQL_Connection/caller)
|
||||
var/static/library_initialized = FALSE
|
||||
if(_BSQL_Initialized())
|
||||
return
|
||||
var/libPath = _BSQL_Library_Path()
|
||||
if(!fexists(libPath))
|
||||
BSQL_DEL_CALL(caller)
|
||||
BSQL_ERROR("Could not find [libPath]!")
|
||||
return
|
||||
|
||||
var/result = _BSQL_Internal_Call("Initialize")
|
||||
if(result)
|
||||
BSQL_DEL_CALL(caller)
|
||||
BSQL_ERROR(result)
|
||||
return
|
||||
_BSQL_Initialized(TRUE)
|
||||
|
||||
/world/proc/_BSQL_Initialized(new_val)
|
||||
var/static/bsql_library_initialized = FALSE
|
||||
if(new_val != null)
|
||||
bsql_library_initialized = new_val
|
||||
return bsql_library_initialized
|
||||
|
||||
/world/BSQL_Shutdown()
|
||||
if(!_BSQL_Initialized())
|
||||
return
|
||||
_BSQL_Internal_Call("Shutdown")
|
||||
_BSQL_Initialized(FALSE)
|
||||
47
code/modules/bsql/core/operation.dm
Normal file
47
code/modules/bsql/core/operation.dm
Normal file
@@ -0,0 +1,47 @@
|
||||
/datum/BSQL_Operation
|
||||
var/datum/BSQL_Connection/connection
|
||||
var/id
|
||||
|
||||
BSQL_PROTECT_DATUM(/datum/BSQL_Operation)
|
||||
|
||||
/datum/BSQL_Operation/New(datum/BSQL_Connection/connection, id)
|
||||
src.connection = connection
|
||||
src.id = id
|
||||
|
||||
BSQL_DEL_PROC(/datum/BSQL_Operation)
|
||||
var/error
|
||||
if(!BSQL_IS_DELETED(connection))
|
||||
error = world._BSQL_Internal_Call("ReleaseOperation", connection.id, id)
|
||||
. = ..()
|
||||
if(error)
|
||||
BSQL_ERROR(error)
|
||||
|
||||
/datum/BSQL_Operation/IsComplete()
|
||||
if(BSQL_IS_DELETED(connection))
|
||||
return TRUE
|
||||
var/result = world._BSQL_Internal_Call("OpComplete", connection.id, id)
|
||||
if(!result)
|
||||
BSQL_ERROR("Error fetching operation [id] for connection [connection.id]!")
|
||||
return
|
||||
return result == "DONE"
|
||||
|
||||
/datum/BSQL_Operation/GetError()
|
||||
if(BSQL_IS_DELETED(connection))
|
||||
return "Connection deleted!"
|
||||
return world._BSQL_Internal_Call("GetError", connection.id, id)
|
||||
|
||||
/datum/BSQL_Operation/GetErrorCode()
|
||||
if(BSQL_IS_DELETED(connection))
|
||||
return -2
|
||||
return text2num(world._BSQL_Internal_Call("GetErrorCode", connection.id, id))
|
||||
|
||||
/datum/BSQL_Operation/WaitForCompletion()
|
||||
if(BSQL_IS_DELETED(connection))
|
||||
return
|
||||
var/error = world._BSQL_Internal_Call("BlockOnOperation", connection.id, id)
|
||||
if(error)
|
||||
if(error == "Operation timed out!") //match this with the implementation
|
||||
return FALSE
|
||||
BSQL_ERROR("Error waiting for operation [id] for connection [connection.id]! [error]")
|
||||
return
|
||||
return TRUE
|
||||
35
code/modules/bsql/core/query.dm
Normal file
35
code/modules/bsql/core/query.dm
Normal file
@@ -0,0 +1,35 @@
|
||||
/datum/BSQL_Operation/Query
|
||||
var/last_result_json
|
||||
var/list/last_result
|
||||
|
||||
BSQL_PROTECT_DATUM(/datum/BSQL_Operation/Query)
|
||||
|
||||
/datum/BSQL_Operation/Query/CurrentRow()
|
||||
return last_result
|
||||
|
||||
/datum/BSQL_Operation/Query/IsComplete()
|
||||
//whole different ballgame here
|
||||
if(BSQL_IS_DELETED(connection))
|
||||
return TRUE
|
||||
var/result = world._BSQL_Internal_Call("ReadyRow", connection.id, id)
|
||||
switch(result)
|
||||
if("DONE")
|
||||
//load the data
|
||||
LoadQueryResult()
|
||||
return TRUE
|
||||
if("NOTDONE")
|
||||
return FALSE
|
||||
else
|
||||
BSQL_ERROR(result)
|
||||
|
||||
/datum/BSQL_Operation/Query/WaitForCompletion()
|
||||
. = ..()
|
||||
if(.)
|
||||
LoadQueryResult()
|
||||
|
||||
/datum/BSQL_Operation/Query/proc/LoadQueryResult()
|
||||
last_result_json = world._BSQL_Internal_Call("GetRow", connection.id, id)
|
||||
if(last_result_json)
|
||||
last_result = json_decode(last_result_json)
|
||||
else
|
||||
last_result = null
|
||||
4
code/modules/bsql/includes.dm
Normal file
4
code/modules/bsql/includes.dm
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "core\connection.dm"
|
||||
#include "core\library.dm"
|
||||
#include "core\operation.dm"
|
||||
#include "core\query.dm"
|
||||
Reference in New Issue
Block a user