You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
1.9 KiB

  1. /datum/BSQL_Connection
  2. var/id
  3. var/connection_type
  4. BSQL_PROTECT_DATUM(/datum/BSQL_Connection)
  5. /datum/BSQL_Connection/New(connection_type, asyncTimeout, blockingTimeout)
  6. if(asyncTimeout == null)
  7. asyncTimeout = BSQL_DEFAULT_TIMEOUT
  8. if(blockingTimeout == null)
  9. blockingTimeout = asyncTimeout
  10. src.connection_type = connection_type
  11. world._BSQL_InitCheck(src)
  12. var/error = world._BSQL_Internal_Call("CreateConnection", connection_type, "[asyncTimeout]", "[blockingTimeout]")
  13. if(error)
  14. BSQL_ERROR(error)
  15. return
  16. id = world._BSQL_Internal_Call("GetConnection")
  17. if(!id)
  18. BSQL_ERROR("BSQL library failed to provide connect operation for connection id [id]([connection_type])!")
  19. BSQL_DEL_PROC(/datum/BSQL_Connection)
  20. var/error
  21. if(id)
  22. error = world._BSQL_Internal_Call("ReleaseConnection", id)
  23. . = ..()
  24. if(error)
  25. BSQL_ERROR(error)
  26. /datum/BSQL_Connection/BeginConnect(ipaddress, port, username, password, database)
  27. var/error = world._BSQL_Internal_Call("OpenConnection", id, ipaddress, "[port]", username, password, database)
  28. if(error)
  29. BSQL_ERROR(error)
  30. return
  31. var/op_id = world._BSQL_Internal_Call("GetOperation")
  32. if(!op_id)
  33. BSQL_ERROR("Library failed to provide connect operation for connection id [id]([connection_type])!")
  34. return
  35. return new /datum/BSQL_Operation(src, op_id)
  36. /datum/BSQL_Connection/BeginQuery(query)
  37. var/error = world._BSQL_Internal_Call("NewQuery", id, query)
  38. if(error)
  39. BSQL_ERROR(error)
  40. return
  41. var/op_id = world._BSQL_Internal_Call("GetOperation")
  42. if(!op_id)
  43. BSQL_ERROR("Library failed to provide query operation for connection id [id]([connection_type])!")
  44. return
  45. return new /datum/BSQL_Operation/Query(src, op_id)
  46. /datum/BSQL_Connection/Quote(str)
  47. if(!str)
  48. return null;
  49. . = world._BSQL_Internal_Call("QuoteString", id, "[str]")
  50. if(!.)
  51. BSQL_ERROR("Library failed to provide quote for [str]!")