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.
 
 
 
 
 
 

133 lines
6.0 KiB

  1. //BSQL - DMAPI v1.2.0.1
  2. //types of connections
  3. #define BSQL_CONNECTION_TYPE_MARIADB "MySql"
  4. #define BSQL_CONNECTION_TYPE_SQLSERVER "SqlServer"
  5. #define BSQL_DEFAULT_TIMEOUT 5
  6. //Call this before rebooting or shutting down your world to clean up gracefully. This invalidates all active connection and operation datums
  7. /world/proc/BSQL_Shutdown()
  8. return
  9. /*
  10. Called whenever a library call is made with verbose information, override and do with as you please
  11. message: English debug message
  12. */
  13. /world/proc/BSQL_Debug(msg)
  14. return
  15. /*
  16. Create a new database connection, does not perform the actual connect
  17. connection_type: The BSQL connection_type to use
  18. asyncTimeout: The timeout to use for normal operations, 0 for infinite, defaults to BSQL_DEFAULT_TIMEOUT
  19. blockingTimeout: The timeout to use for blocking operations, must be less than or equal to asyncTimeout, 0 for infinite, defaults to asyncTimeout
  20. */
  21. /datum/BSQL_Connection/New(connection_type, asyncTimeout, blockingTimeout)
  22. return ..()
  23. /*
  24. Starts an operation to connect to a database. Should only have 1 successful call
  25. ipaddress: The ip/hostname of the target server
  26. port: The port of the target server
  27. username: The username to login to the target server
  28. password: The password for the target server
  29. database: Optional database to connect to. Must be used when trying to do database operations, `USE x` is not sufficient
  30. Returns: A /datum/BSQL_Operation representing the connection or null if an error occurred
  31. */
  32. /datum/BSQL_Connection/proc/BeginConnect(ipaddress, port, username, password, database)
  33. return
  34. /*
  35. Properly quotes a string for use by the database. The connection must be open for this proc to succeed
  36. str: The string to quote
  37. Returns: The string quoted on success, null on error
  38. */
  39. /datum/BSQL_Connection/proc/Quote(str)
  40. return
  41. /*
  42. Starts an operation for a query
  43. query: The text of the query. Only one query allowed per invocation, no semicolons
  44. Returns: A /datum/BSQL_Operation/Query representing the running query and subsequent result set or null if an error occurred
  45. Note for MariaDB: The underlying connection is pooled. In order to use connection state based properties (i.e. LAST_INSERT_ID()) you can guarantee multiple queries will use the same connection by running BSQL_DEL_CALL(query) on the finished /datum/BSQL_Operation/Query and then creating the next one with another call to BeginQuery() with no sleeps in between
  46. */
  47. /datum/BSQL_Connection/proc/BeginQuery(query)
  48. return
  49. /*
  50. Checks if the operation is complete. This, in some cases must be called multiple times with false return before a result is present regardless of timespan. For best performance check it once per tick
  51. Returns: TRUE if the operation is complete, FALSE if it's not, null on error
  52. */
  53. /datum/BSQL_Operation/proc/IsComplete()
  54. return
  55. /*
  56. Blocks the entire game until the given operation completes. IsComplete should not be checked after calling this to avoid potential side effects.
  57. Returns: TRUE on success, FALSE if the operation wait time exceeded the connection's blockingTimeout setting
  58. */
  59. /datum/BSQL_Operation/proc/WaitForCompletion()
  60. return
  61. /*
  62. Get the error message associated with an operation. Should not be used while IsComplete() returns FALSE
  63. Returns: The error message, if any. null otherwise
  64. */
  65. /datum/BSQL_Operation/proc/GetError()
  66. return
  67. /*
  68. Get the error code associated with an operation. Should not be used while IsComplete() returns FALSE
  69. Returns: The error code, if any. null otherwise
  70. */
  71. /datum/BSQL_Operation/proc/GetErrorCode()
  72. return
  73. /*
  74. Gets an associated list of column name -> value representation of the most recent row in the query. Only valid if IsComplete() returns TRUE. If this returns null and no errors are present there are no more results in the query. Important to note that once IsComplete() returns TRUE it must not be called again without checking this or the row values may be lost
  75. Returns: An associated list of column name -> value for the row. Values will always be either strings or null
  76. */
  77. /datum/BSQL_Operation/Query/proc/CurrentRow()
  78. return
  79. /*
  80. Code configuration options below
  81. Define this to avoid modifying this file but the following defines must be declared somewhere else before BSQL/includes.dm is included
  82. */
  83. #ifndef BSQL_EXTERNAL_CONFIGURATION
  84. //Modify this if you disagree with byond's GC schemes. Ensure this is called for all connections and operations when they are deleted or they will leak native resources until /world/proc/BSQL_Shutdown() is called
  85. #define BSQL_DEL_PROC(path) ##path/Del()
  86. //The equivalent of calling del() in your codebase
  87. #define BSQL_DEL_CALL(obj) del(##obj)
  88. //Returns TRUE if an object is delete
  89. #define BSQL_IS_DELETED(obj) (obj == null)
  90. //Modify this to add protections to the connection and query datums
  91. #define BSQL_PROTECT_DATUM(path)
  92. //Modify this to change up error handling for the library
  93. #define BSQL_ERROR(message) CRASH("BSQL: [##message]")
  94. #endif
  95. /*
  96. Copyright 2018 Jordan Brown
  97. 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:
  98. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  99. 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.
  100. */