Mstdlib-1.24.0
m_sql_driver.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2017 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef __M_SQL_DRIVER_H__
25#define __M_SQL_DRIVER_H__
26
27/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28
29#include <mstdlib/base/m_defs.h>
30#include <mstdlib/base/m_types.h>
31#include <mstdlib/mstdlib_sql.h>
32/* Needed for M_module_handle_t */
33#include <mstdlib/sql/m_module.h>
34
35/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37__BEGIN_DECLS
38
39
40/*! \addtogroup m_sql_driver SQL Module/Driver
41 * \ingroup m_sql
42 *
43 * SQL Module/Driver definitions and helpers.
44 *
45 * These functions are used only by the internal implementation and custom
46 * loaded drivers. Typically an integrator would never use these unless they
47 * are developing their own custom SQL driver. If so, they would
48 * \code{.c}
49 * #include <mstdlib/sql/m_sql_driver.h>
50 * \endcode
51 * To gain access to these functions.
52 *
53 * @{
54 */
55
56/*! Current subsystem versioning for module compatibility tracking */
57#define M_SQL_DRIVER_VERSION 0x0100
58
59/*! Private connection object structure from pool */
60struct M_sql_conn;
61/*! Private connection object */
62typedef struct M_sql_conn M_sql_conn_t;
63
64/*! Driver-defined private storage for connection pool */
65struct M_sql_driver_connpool;
66
67/*! Driver-defined private storage for connection pool (typedef) */
68typedef struct M_sql_driver_connpool M_sql_driver_connpool_t;
69
70/*! Driver-defined private storage for connection object */
71struct M_sql_driver_conn;
72
73/*! Driver-defined private storage for connection object (typedef) */
74typedef struct M_sql_driver_conn M_sql_driver_conn_t;
75
76/*! Driver-defined private storage for a statement handle */
77struct M_sql_driver_stmt;
78
79/*! Driver-defined private storage for a statement handle (typedef) */
80typedef struct M_sql_driver_stmt M_sql_driver_stmt_t;
81
82
83
84/*! Callback called when the module is loaded. If there is any global environment that needs
85 * to be set up, it should be called here. This is guaranteed to only be called once.
86 *
87 * \param[out] error User-supplied buffer to hold an error message
88 * \param[in] error_size Size of user-supplied error buffer.
89 * \return M_TRUE on success, M_FALSE on failure
90 */
91typedef M_bool (*M_sql_driver_cb_init_t)(char *error, size_t error_size);
92
93/*! Callback called when the module is unloaded. If there is any global environment that needs
94 * to be destroyed, it should be called here. This is guaranteed to only be called once
95 * and only after a successful M_sql_driver_cb_init_t.
96 */
97typedef void (*M_sql_driver_cb_destroy_t)(void);
98
99/*! Callback called when a pool is created or updated with a read-only pool. A dictionary of
100 * configuration is passed for the connection pool type (primary vs readonly).
101 *
102 * Any parameters needed should be saved into the private handle returned. The dictionaries
103 * passed in should be strictly validated using, at a minimum, M_sql_driver_validate_connstr().
104 *
105 * \param[in,out] dpool Driver-specific pool handle. Should be initailized if passed in as
106 * NULL. Currently the only time that occurs is when is_readonly is M_FALSE.
107 * Only a single driver-specific pool is created for all pool types
108 * (primary, readonly), so if an initialized object is passed in, the
109 * additional configuration data needs to be appended to the current object.
110 * \param[in] pool Partially initialized pool, mostly used for getting other metadata for
111 * verification (e.g. username/password)
112 * \param[in] is_readonly M_TRUE if the pool being initialized is readonly, M_FALSE if primary.
113 * \param[in] conndict Configuration dictionary of parameters
114 * \param[out] num_hosts The number of hosts contained within the configuration for load balancing or failover purposes.
115 * \param[out] error User-supplied buffer to output an error message.
116 * \param[in] error_size Size of user-supplied error buffer.
117 * \return M_TRUE on success, M_FALSE on failure
118 */
119typedef M_bool (*M_sql_driver_cb_createpool_t)(M_sql_driver_connpool_t **dpool, M_sql_connpool_t *pool, M_bool is_readonly, const M_hash_dict_t *conndict, size_t *num_hosts, char *error, size_t error_size);
120
121/*! Callback called when the pool is destroyed to free the driver-specific pool object
122 *
123 * \param[in] dpool Pool object to be destroyed
124 */
126
127/*! Callback called to initialize a new connection to the database.
128 * \param[out] conn Initialized private connection object is returned on success.
129 * \param[in] pool Pool handle, use M_sql_driver_pool_get_dpool() to get driver-specific pool handle.
130 * \param[in] is_readonly_pool M_TRUE if the connection references a read-only pool, or M_FALSE if the primary pool.
131 * \param[in] host_idx Host index to use (if multiple hosts configured and returned by #M_sql_driver_cb_createpool_t), 0 based.
132 * \param[out] error User-supplied buffer to output an error message.
133 * \param[in] error_size Size of user-supplied error buffer.
134 * \return M_SQL_ERROR_SUCCESS on success, or one of the M_sql_error_t errors
135 */
136typedef M_sql_error_t (*M_sql_driver_cb_connect_t)(M_sql_driver_conn_t **conn, M_sql_connpool_t *pool, M_bool is_readonly_pool, size_t host_idx, char *error, size_t error_size);
137
138/*! Callback called to get the server version string/information
139 * \param[in] conn Private connection object.
140 * \return String indicating server name and version in an implementation-defined manner
141 */
142typedef const char *(*M_sql_driver_cb_serverversion_t)(M_sql_driver_conn_t *conn);
143
144/*! Callback called after each connection is successfully established. The is_first_in_pool can be
145 * used to key off of to ensure if the action only needs to be performed once for the lifetime of
146 * the pool after connectivity is established, it can be done there.
147 *
148 * Examples of use for this callback include setting SQLite journal mode, performing an SQLite
149 * analyze or integrity check. For other databases, this may be where custom store procedures
150 * are created, or default transaction isolation levels are set.
151 *
152 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
153 * private connection handle.
154 * \param[in] dpool Driver-specific pool handle returned from #M_sql_driver_cb_createpool_t
155 * \param[in] is_first_in_pool M_TRUE if first connection in a pool to be established, M_FALSE if secondary connection.
156 * \param[in] is_readonly M_TRUE if this is referencing the readonly pool, M_FALSE if the normal pool
157 * \param[out] error User-supplied buffer to output an error message.
158 * \param[in] error_size Size of user-supplied error buffer.
159 * \return M_SQL_ERROR_SUCCESS on success, or one of the M_sql_error_t errors
160 */
161typedef M_sql_error_t (*M_sql_driver_cb_connect_runonce_t)(M_sql_conn_t *conn, M_sql_driver_connpool_t *dpool, M_bool is_first_in_pool, M_bool is_readonly, char *error, size_t error_size);
162
163
164/*! Callback called to disconnect and destroy all metadata associated with a connection.
165 * \param[in] conn Private driver-specific connection handle to be disconnected and destroyed
166 */
168
169/*! Rewrite the user-provided query string to one more easily consumed by the database
170 * backend.
171 *
172 * It is suggested implementors use M_sql_driver_queryformat() if possible instead of
173 * writing this from scratch.
174 *
175 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
176 * private connection handle.
177 * \param[in] query User-provided query string
178 * \param[in] num_params Number of bound parameters (per row)
179 * \param[in] num_rows For insert statements, number of rows of bound parameters
180 * \param[in] error User-supplied error message buffer
181 * \param[in] error_size Size of user-supplied error message buffer
182 * \return Allocated buffer containing a rewritten query string or NULL on failure
183 */
184typedef char *(*M_sql_driver_cb_queryformat_t)(M_sql_conn_t *conn, const char *query, size_t num_params, size_t num_rows, char *error, size_t error_size);
185
186/*! Return number of rows that will be worked on for the current execution.
187 *
188 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
189 * private connection handle.
190 * \param[in] num_params Number of bound parameters (per row)
191 * \param[in] num_rows For insert statements, number of rows of bound parameters
192 * \return Row count
193 */
194typedef size_t (*M_sql_driver_cb_queryrowcnt_t)(M_sql_conn_t *conn, size_t num_params, size_t num_rows);
195
196/*! Prepare the provided query for execution.
197 *
198 * \param[in,out] driver_stmt Driver-specific statement handle. If executing based on a cached
199 * prepared statement handle, may pass in existing handle. Handle used
200 * will always be returned (may or may not be identical to passed in handle)
201 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
202 * private connection handle.
203 * \param[in] stmt Statement handle containing all the details necessary for preparation
204 * \param[in] error User-supplied error message buffer
205 * \param[in] error_size Size of user-supplied error message buffer
206 * \return M_SQL_ERROR_SUCCESS on success, or one of the M_sql_error_t errors on failure
207 */
208typedef M_sql_error_t (*M_sql_driver_cb_prepare_t)(M_sql_driver_stmt_t **driver_stmt, M_sql_conn_t *conn, M_sql_stmt_t *stmt, char *error, size_t error_size);
209
210/*! Destroy the driver-specific prepared statement handle.
211 *
212 * \param[in] stmt Driver-specific statement handle to be destroyed.
213 */
215
216/*! Execute the query.
217 *
218 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
219 * private connection handle.
220 * \param[in] stmt Driver-specific statement handle to be executed as returned by M_sql_driver_cb_prepare_t
221 * \param[out] rows_executed For drivers that support multiple rows being inserted in a single query, this is how
222 * many bind parameter rows were actually inserted by the query. This value may be up to
223 * M_sql_driver_stmt_bind_rows() in size. Execute will be called in a loop if not all rows
224 * were executed in a single query until complete (with each iteration decrementing the
225 * visible M_sql_driver_stmt_bind_rows()).
226 * \param[in] error User-supplied error message buffer
227 * \param[in] error_size Size of user-supplied error message buffer
228 * \return one of the M_sql_error_t conditions
229 */
230typedef M_sql_error_t (*M_sql_driver_cb_execute_t)(M_sql_conn_t *conn, M_sql_stmt_t *stmt, size_t *rows_executed, char *error, size_t error_size);
231
232/*! Fetch rows from server
233 *
234 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
235 * private connection handle.
236 * \param[in] stmt System statement object, use M_sql_driver_stmt_get_stmt() to fetch driver-specific statement handle.
237 * \param[in] error User-supplied error message buffer
238 * \param[in] error_size Size of user-supplied error message buffer
239 * \return one of the M_sql_error_t conditions
240 */
241typedef M_sql_error_t (*M_sql_driver_cb_fetch_t)(M_sql_conn_t *conn, M_sql_stmt_t *stmt, char *error, size_t error_size);
242
243/*! Begin a transaction on the server with the specified isolation level.
244 *
245 * If the isolation level is not supported by the server, the closet match should be chosen.
246 *
247 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
248 * private connection handle.
249 * \param[in] isolation Requested isolation level
250 * \param[out] error User-supplied error message buffer
251 * \param[in] error_size Size of user-supplied error message buffer
252 * \return one of the M_sql_error_t conditions
253 */
254typedef M_sql_error_t (*M_sql_driver_cb_begin_t)(M_sql_conn_t *conn, M_sql_isolation_t isolation, char *error, size_t error_size);
255
256/*! Rollback a transaction.
257 *
258 * The connection object should retain enough metadata to know if there is a current open transaction
259 * or not, so that if the transaction was already implicitly closed by a failed previous request,
260 * this should be a no-op.
261 *
262 * If the rollback fails when it is expected to succeed, the driver should probably return a code
263 * to indicate a critical connectivity failure has occurred to kill the connection.
264 *
265 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
266 * private connection handle.
267 * \return one of the M_sql_error_t conditions
268 */
270
271/*! Commit a transaction.
272 *
273 * If a commit fails, the transaction must be automatically rolled back by the driver.
274 *
275 * \param[in] conn Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific
276 * private connection handle.
277 * \param[out] error User-supplied error message buffer
278 * \param[in] error_size Size of user-supplied error message buffer
279 * \return one of the M_sql_error_t conditions
280 */
281typedef M_sql_error_t (*M_sql_driver_cb_commit_t)(M_sql_conn_t *conn, char *error, size_t error_size);
282
283/*! Output the SQL-driver specific data type to the supplied buffer based on the input type and
284 * maximum length.
285 *
286 * \param[in] pool Pointer to connection pool object
287 * \param[in,out] buf Buffer to write sql-server-specific data type into.
288 * \param[in] type mstdlib sql data type
289 * \param[in] max_len Maximum length of data type. Meaningful for Text and Binary types only,
290 * or use 0 for maximum supported server size.
291 * \param[in] is_cast Used to convert to data type for server.
292 * \return M_TRUE on success, M_FALSE on error such as misuse
293 */
294typedef M_bool (*M_sql_driver_cb_datatype_t)(M_sql_connpool_t *pool, M_buf_t *buf, M_sql_data_type_t type, size_t max_len, M_bool is_cast);
295
296/*! Append an SQL-driver specific suffix to the end of the provided CREATE TABLE query.
297 *
298 * Some servers like MySQL append things like " ENGINE=InnoDB CHARSET=utf8"
299 *
300 * \param[in] pool SQL Server pool, use M_sql_driver_pool_get_dpool() to get driver-specific
301 * pool metadata. Create Table is always executed against the primary subpool.
302 * \param[in,out] query Query string to append suffix
303 */
305
306
307/*! Output the SQL-driver-specific update lock as needed.
308 *
309 * See M_sql_query_append_updlock() for more information.
310 *
311 * \param[in] pool Pointer to connection pool object
312 * \param[in,out] query Buffer to write sql-server-specific lock information into.
313 * \param[in] type mstdlib sql updlock type
314 * \param[in] table_name Table name for "FOR UPDATE OF" style locks
315 */
316typedef void (*M_sql_driver_cb_append_updlock_t)(M_sql_connpool_t *pool, M_buf_t *query, M_sql_query_updlock_type_t type, const char *table_name);
317
318
319/*! Output the SQL-driver-specific bit operation formatted as needed.
320 *
321 * See M_sql_query_append_bitop() for more information.
322 *
323 * \param[in] pool Pointer to connection pool object
324 * \param[in,out] query Buffer to write sql-server-specific bitop into
325 * \param[in] op Bitwise operation to perform.
326 * \param[in] exp1 Left-hand side of SQL expression.
327 * \param[in] exp2 Right-hande size of SQL expression.
328 * \return M_TRUE on success, M_FALSE on misuse.
329 */
330typedef M_bool (*M_sql_driver_cb_append_bitop_t)(M_sql_connpool_t *pool, M_buf_t *query, M_sql_query_bitop_t op, const char *exp1, const char *exp2);
331
332
333/*! Rewrite index identifier name to comply with database limitations.
334 *
335 * For instance, Oracle versions prior to 12c R2 has a limitation of 30 characters
336 * for identifiers. We need to rewrite the index name if the database version
337 * matches.
338 *
339 * \param[in] pool Pointer to connection pool object
340 * \param[in] index_name Desired index name
341 * \return NULL if no change necessary, otherwise rewritten index name.
342 */
343typedef char *(*M_sql_driver_cb_rewrite_indexname_t)(M_sql_connpool_t *pool, const char *index_name);
344
345/*! Flags advertised by SQL database (could be based on db version etc) */
346typedef enum {
347 M_SQL_DRIVER_FLAG_NONE = 0, /*!< No flags */
348 M_SQL_DRIVER_FLAG_UNIQUEINDEX_NOTNULL_WHERE = 1 << 0 /*!< A unique index needs a WHERE clause to allow multiple NULL values */
350
351/*! Fetch current flags from driver for connection based
352 *
353 * \param[in] conn Initialized connection object.
354 * \return NULL if no change necessary, otherwise rewritten index name.
355 */
357
358
359/*! Structure to be implemented by SQL drivers with information about the database in use */
360typedef struct {
361 M_uint16 driver_sys_version; /*!< Driver/Module subsystem version, use M_SQL_DRIVER_VERSION */
362 const char *name; /*!< Short name of module */
363 const char *display_name; /*!< Display name of module */
364 const char *version; /*!< Internal module version */
365
366 /* NOTE: All callbacks are required to be registered by all drivers */
367 M_sql_driver_cb_flags_t cb_flags; /*!< Optional. Callback used to get db flags */
368 M_sql_driver_cb_init_t cb_init; /*!< Required. Callback used for module initialization. */
369 M_sql_driver_cb_destroy_t cb_destroy; /*!< Required. Callback used for module destruction/unloading. */
370 M_sql_driver_cb_createpool_t cb_createpool; /*!< Required. Callback used for pool creation */
371 M_sql_driver_cb_destroypool_t cb_destroypool; /*!< Required. Callback used for pool destruction */
372 M_sql_driver_cb_connect_t cb_connect; /*!< Required. Callback used for connecting to the db */
373 M_sql_driver_cb_serverversion_t cb_serverversion; /*!< Required. Callback used to get the server name/version string */
374 M_sql_driver_cb_connect_runonce_t cb_connect_runonce; /*!< Optional. Callback used after connection is established, but before first query to set run-once options. */
375 M_sql_driver_cb_disconnect_t cb_disconnect; /*!< Required. Callback used to disconnect from the db */
376 M_sql_driver_cb_queryformat_t cb_queryformat; /*!< Required. Callback used for reformatting a query to the sql db requirements */
377 M_sql_driver_cb_queryrowcnt_t cb_queryrowcnt; /*!< Required. Callback used for determining how many rows will be processed by the current execution (chunking rows) */
378 M_sql_driver_cb_prepare_t cb_prepare; /*!< Required. Callback used for preparing a query for execution */
379 M_sql_driver_cb_prepare_destroy_t cb_prepare_destroy; /*!< Required. Callback used to destroy the driver-specific prepared statement handle */
380 M_sql_driver_cb_execute_t cb_execute; /*!< Required. Callback used for executing a prepared query */
381 M_sql_driver_cb_fetch_t cb_fetch; /*!< Required. Callback used to fetch result data/rows from server */
382 M_sql_driver_cb_begin_t cb_begin; /*!< Required. Callback used to begin a transaction */
383 M_sql_driver_cb_rollback_t cb_rollback; /*!< Required. Callback used to rollback a transaction */
384 M_sql_driver_cb_commit_t cb_commit; /*!< Required. Callback used to commit a transaction */
385 M_sql_driver_cb_datatype_t cb_datatype; /*!< Required. Callback used to convert to data type for server */
386 M_sql_driver_cb_createtable_suffix_t cb_createtable_suffix; /*!< Optional. Callback used to append additional data to the Create Table query string */
387 M_sql_driver_cb_append_updlock_t cb_append_updlock; /*!< Optional. Callback used to append row-level locking data */
388 M_sql_driver_cb_append_bitop_t cb_append_bitop; /*!< Required. Callback used to append a bit operation */
389 M_sql_driver_cb_rewrite_indexname_t cb_rewrite_indexname; /*!< Optional. Callback used to rewrite an index name to comply with DB requirements */
390 M_module_handle_t handle; /*!< Handle for loaded driver - must be initialized to NULL in the driver structure */
392
393
394/*! Flags for the helper query string format rewrite function M_sql_driver_queryformat() */
395typedef enum {
396 M_SQL_DRIVER_QUERYFORMAT_NORMAL = 0, /*!< Normal, strips any query terminator otherwise unmodified */
397 M_SQL_DRIVER_QUERYFORMAT_TERMINATOR = 1 << 0, /*!< Query terminator (;) is required */
398 M_SQL_DRIVER_QUERYFORMAT_ENUMPARAM_DOLLAR = 1 << 1, /*!< Instead of using ? for each bound parameter, parameters
399 take the form of $1, $2, ... $N (used by PostgreSQL) */
400 M_SQL_DRIVER_QUERYFORMAT_ENUMPARAM_COLON = 1 << 2, /*!< Instead of using ? for each bound parameter, parameters
401 take the form of :1, :2, ... :N (used by Oracle) */
402 M_SQL_DRIVER_QUERYFORMAT_MULITVALUEINSERT_CD = 1 << 3, /*!< Multiple-value/row insertions are not sent to the server using
403 rows of bound parameters, but instead by comma-delimiting the
404 values in the insert statement. This will rewrite an INSERT
405 statement from "INSERT INTO foo VALUES (?, ?, ?)" into something
406 like "INSERT INTO foo VALUES (?, ?, ?), (?, ?, ?), ..., (?, ?, ?)" */
407 M_SQL_DRIVER_QUERYFORMAT_INSERT_ONCONFLICT_DONOTHING = 1 << 4, /*!< Some databases may choose to abort the entire transaction on a
408 * conflict, but there are times we explicitly want to take action
409 * on such a case without rolling back. This clause will cause it to
410 * skip the insert of that record. PostgreSQL is known to behave this
411 * way. However, this means the result will not return said conflict
412 * so we must check to see if the return count is expected, and if
413 * not, rewrite the code to assume it is a conflict */
415
416
417/*! Rewrite the user-provided query string to one more easily consumed by the database
418 * backend based on a series of flags.
419 *
420 * This is a helper function to reduce code duplication in database implementations and
421 * is exclusively called by the drivers. If the implementation here is insufficient for
422 * the requirements of the SQL server, then it is up to the driver to implement their own
423 * routine
424 *
425 * \param[in] query User-provided query string
426 * \param[in] flags Bitmap of M_sql_driver_queryformat_flags_t Flags controlling behavior of processor
427 * \param[in] num_params Number of bound parameters (per row)
428 * \param[in] num_rows For insert statements, number of rows of bound parameters
429 * \param[in] error User-supplied error message buffer
430 * \param[in] error_size Size of user-supplied error message buffer
431 * \return Allocated buffer containing a rewritten query string or NULL on failure
432 */
433M_API char *M_sql_driver_queryformat(const char *query, M_uint32 flags, size_t num_params, size_t num_rows, char *error, size_t error_size);
434
435/*! Connection string argument value allowed */
436typedef enum {
443
444
445/*! Structure defining possible connection string parameters to be passed to
446 * M_sql_driver_validate_connstr() to notify callers of possible typos */
448 const char *name; /*!< Parameter name (case-insensitive) */
449 M_sql_connstr_type_t type; /*!< Data type of parameter */
450 M_bool required; /*!< Whether or not the parameter is required */
451 size_t min_len; /*!< Minimum length of parameter when present */
452 size_t max_len; /*!< Maximum length of parameter when present */
453};
454
455/*! Typedef for struct M_sql_connstr_params */
456typedef struct M_sql_connstr_params M_sql_connstr_params_t;
457
458/*! Host/port used with M_sql_driver_parse_hostport() */
459typedef struct {
460 char host[256];
461 M_uint16 port;
463
464
465/*! Connection state tracking */
466typedef enum {
467 M_SQL_CONN_STATE_OK = 1, /*!< Connection state is good */
468 M_SQL_CONN_STATE_ROLLBACK = 2, /*!< A rollback condition has been hit, must be returned to the pool to be cleared */
469 M_SQL_CONN_STATE_FAILED = 3 /*!< The connection has failed, must be destroyed (return to the pool will do this) */
471
472/*! Get the current connection state.
473 *
474 * \param[in] conn Connection acquired with M_sql_connpool_acquireconn()
475 * \return connection state
476 */
478
479
480/*! Base helper used to execute a statement on a connection handle.
481 *
482 * This helper is called by M_sql_stmt_execute() and M_sql_trans_execute()
483 *
484 * \param[in] conn Connection acquired with M_sql_connpool_acquireconn()
485 * \param[in] stmt Prepared statement object to be executed
486 * \return one of the M_sql_error_t codes
487 */
489
490/*! Base helper used to execute a simple query (no bound parameters) on a connection handle.
491 *
492 * This internally generates a statement handle and destroys it upon completion.
493 *
494 * \param[in] conn Connection acquired with M_sql_connpool_acquireconn()
495 * \param[in] query Direct query to be executed.
496 * \param[in] skip_sanity_checks Skip sanity checks that may otherwise fail. Usually used for injecting a stored procedure at db init.
497 * \return one of the M_sql_error_t codes
498 */
499M_API M_sql_stmt_t *M_sql_conn_execute_simple(M_sql_conn_t *conn, const char *query, M_bool skip_sanity_checks);
500
501/*! Helper for SQL drivers to validate the connection strings provided.
502 *
503 * \param[in] conndict Dictionary of key/value pairs passed to driver
504 * \param[in] params NULL-terminated structure of parameters to validate.
505 * \param[out] error User-supplied error buffer to output error message.
506 * \param[in] error_size Size of user-supplied error buffer.
507 * \return M_TRUE on success, M_FALSE on failure.
508 */
509M_API M_bool M_sql_driver_validate_connstr(const M_hash_dict_t *conndict, const M_sql_connstr_params_t *params, char *error, size_t error_size);
510
511M_API M_sql_hostport_t *M_sql_driver_parse_hostport(const char *hostport, M_uint16 default_port, size_t *out_len, char *error, size_t error_size);
512
513/*! Retrieve a handle to the driver-specific connection object.
514 *
515 * \param[in] conn Connection acquired with M_sql_connpool_acquireconn()
516 *
517 * \return handle to driver-specific connection object
518 */
528
529/*! Return whether or not the connection is used within an SQL
530 * transaction, or simply a single standalone query.
531 *
532 * \param[in] conn Initialized #M_sql_conn_t
533 * \return M_TRUE if used within a transaction, M_FALSE for single standalone query
534 */
536
540
541/*! Retrieve remaining unprocessed row count.
542 *
543 * Rows returned, and rows passed in may not accurately reflect the number
544 * of rows of parameters actually bound. Some SQL servers do not support
545 * multiple rows being inserted in a single query, or may have a limit on
546 * how many rows can be inserted at once ... so this is the current 'view'
547 * that adjusts for rows that have already been processed so the sql driver
548 * doesn't have to track it
549 *
550 * \param[in] stmt Initialized statement handle
551 * \return unprocessed rows remaining
552 */
554
555/*! Retrieve column count per row, or if a single row or a query that does not
556 * support multiple rows (e.g. select), the entire number of parameters bound.
557 *
558 * This is NOT the number of bound params for multi-row binding, this is just
559 * the number of columns in a single row.
560 *
561 * \param[in] stmt Initialized statement handle
562 * \return bind column count
563 */
565
566
568
569/*! Some columns with multiple rows might have a NULL data type bound with the wrong type,
570 * this searches for the "real" datatype, first non-null */
572
573/*! Get the maximum size of a column if there are multiple rows bound, taking into account things like integer sizes */
575
576/*! Get the current size of the row/column in bytes, taking into account things like integer sizes */
577M_API size_t M_sql_driver_stmt_bind_get_curr_col_size(M_sql_stmt_t *stmt, size_t row, size_t col);
578
579
580/*! Get the requested row count as requested by the user by M_sql_stmt_set_max_fetch_rows().
581 *
582 * This value can be used to set a Prefetch Row setting for receiving rows from the
583 * server as an optimization. If a value of 0 is returned, this means the customer
584 * did not request partial fetching (user wants all rows), so the server might want
585 * to choose an internal default size.
586 *
587 * \param[in] stmt Initialized statement handle
588 * \return rows requested per fetch, or 0 if user wants all rows
589 */
591
592M_API M_bool *M_sql_driver_stmt_bind_get_bool_addr(M_sql_stmt_t *stmt, size_t row, size_t idx);
593M_API M_int16 *M_sql_driver_stmt_bind_get_int16_addr(M_sql_stmt_t *stmt, size_t row, size_t idx);
594M_API M_int32 *M_sql_driver_stmt_bind_get_int32_addr(M_sql_stmt_t *stmt, size_t row, size_t idx);
595M_API M_int64 *M_sql_driver_stmt_bind_get_int64_addr(M_sql_stmt_t *stmt, size_t row, size_t idx);
596M_API M_bool M_sql_driver_stmt_bind_get_bool(M_sql_stmt_t *stmt, size_t row, size_t idx);
597M_API M_int16 M_sql_driver_stmt_bind_get_int16(M_sql_stmt_t *stmt, size_t row, size_t idx);
598M_API M_int32 M_sql_driver_stmt_bind_get_int32(M_sql_stmt_t *stmt, size_t row, size_t idx);
599M_API M_int64 M_sql_driver_stmt_bind_get_int64(M_sql_stmt_t *stmt, size_t row, size_t idx);
600M_API M_bool M_sql_driver_stmt_bind_isnull(M_sql_stmt_t *stmt, size_t row, size_t idx);
601M_API const char *M_sql_driver_stmt_bind_get_text(M_sql_stmt_t *stmt, size_t row, size_t idx);
602M_API size_t M_sql_driver_stmt_bind_get_text_len(M_sql_stmt_t *stmt, size_t row, size_t idx);
603M_API const M_uint8 *M_sql_driver_stmt_bind_get_binary(M_sql_stmt_t *stmt, size_t row, size_t idx);
604M_API size_t M_sql_driver_stmt_bind_get_binary_len(M_sql_stmt_t *stmt, size_t row, size_t idx);
605
606/*! Set the number of affected rows from things like UPDATE or DELETE
607 *
608 * \param[in] stmt Statement handle
609 * \param[in] cnt Count to set
610 * \return M_TRUE on succes, M_FALSE on failure such as misuse
611 */
613
614
615/*! Set the column count for the row headers
616 *
617 * \param[in] stmt Statement handle
618 * \param[in] cnt Count to set
619 * \return M_TRUE on succes, M_FALSE on failure such as misuse or column count has already been set
620 */
622
623/*! Sets the column header name for the specified column
624 *
625 * Must only be called after M_sql_driver_stmt_result_set_num_cols()
626 *
627 * \param[in] stmt Statement handle
628 * \param[in] col Column to modify
629 * \param[in] name Name to set
630 * \return M_TRUE on success, or M_FALSE on failure such as misuse
631 */
632M_API M_bool M_sql_driver_stmt_result_set_col_name(M_sql_stmt_t *stmt, size_t col, const char *name);
633
634/*! Sets the column header name for the specified column
635 *
636 * Must only be called after M_sql_driver_stmt_result_set_num_cols()
637 *
638 * \param[in] stmt Statement handle
639 * \param[in] col Column to modify
640 * \param[in] type Column type to set
641 * \param[in] max_size Maximum size of column (for text or binary data), if available. 0 otherwise.
642 * \return M_TRUE on success, or M_FALSE on failure such as misuse
643 */
644M_API M_bool M_sql_driver_stmt_result_set_col_type(M_sql_stmt_t *stmt, size_t col, M_sql_data_type_t type, size_t max_size);
645
646/*! Start a new data column, returning writable buffer to hold column
647 * data.
648 *
649 * The data written to the buffer is the Text or Binary version of the data.
650 *
651 * \note ALL data except NULL columns must write at least a NULL terminator,
652 * even binary data requires a NULL terminator even though it won't be
653 * indicated in the final length. Any fields added without at least
654 * a NULL terminator will be considered NULL fields.
655 *
656 * The text version is also used for Integer and Boolean values. If the column
657 * is NULL, do not write any data, not even a NULL terminator.
658 *
659 * Must only be called after M_sql_driver_stmt_result_set_num_cols(), and highly
660 * recommended to have previously called M_sql_driver_stmt_result_set_col_name()
661 * and M_sql_driver_stmt_result_set_col_type().
662 *
663 * Binary data can only be written if M_sql_driver_stmt_result_set_col_type() is
664 * set to #M_SQL_DATA_TYPE_BINARY.
665 *
666 * \param[in] stmt Statement handle
667 * \return Allocated #M_buf_t to write data. Or NULL on failure such as no more
668 * eligible columns for row.
669 */
671
672/*! Finish a row worth of data.
673 *
674 * This is required to be called after all the columns for a row are written using
675 * M_sql_driver_stmt_result_col_start().
676 *
677 * \param[in] stmt Statement handle
678 * \return M_TRUE on success, or M_FALSE on error, such as not all columns written.
679 */
681
682/*! Capabilities driver can use for M_sql_driver_append_updlock() helper */
683typedef enum {
684 M_SQL_DRIVER_UPDLOCK_CAP_NONE = 0, /*!< No row-level locks supported */
685 M_SQL_DRIVER_UPDLOCK_CAP_FORUPDATE = 1, /*!< FOR UPDATE style locks */
686 M_SQL_DRIVER_UPDLOCK_CAP_MSSQL = 2, /*!< Microsoft SQL Server style locks */
687 M_SQL_DRIVER_UPDLOCK_CAP_FORUPDATEOF = 3 /*!< FOR UPDATE, and FOR UPDATE OF (PostgreSQL) style locks */
689
690
691/*! Helper for drivers to implement M_sql_driver_cb_append_updlock_t
692 *
693 * \param[in] caps Capabilities of SQL server
694 * \param[in,out] query Buffer to write sql-server-specific lock information into.
695 * \param[in] type mstdlib sql updlock type
696 * \param[in] table_name Table name for M_SQL_DRIVER_UPDLOCK_CAP_FORUPDATEOF
697 */
699
700
701/*! Bit Operations capabilities/type used by SQL server */
702typedef enum {
703 M_SQL_DRIVER_BITOP_CAP_OP = 1, /*!< SQL server supports direct operators */
704 M_SQL_DRIVER_BITOP_CAP_FUNC = 2, /*!< SQL server supports BITOR and BITAND functions */
705 M_SQL_DRIVER_BITOP_CAP_OP_CAST_BIGINT = 3 /*!< SQL server supports direct operators, but needs exp2 input cast as BIGINT */
707
708
709/*! Helper for drivers to implement M_sql_driver_cb_append_bitop_t
710 *
711 * \param[in] caps Capabilities of SQL server
712 * \param[in,out] query Buffer to write sql-server-specific bitop into
713 * \param[in] op Bitwise operation to perform.
714 * \param[in] exp1 Left-hand side of SQL expression.
715 * \param[in] exp2 Right-hande size of SQL expression.
716 * \return M_TRUE on success, M_FALSE on misuse
717 */
718M_API M_bool M_sql_driver_append_bitop(M_sql_driver_bitop_caps_t caps, M_buf_t *query, M_sql_query_bitop_t op, const char *exp1, const char *exp2);
719
720
723
724/*! Generate a driver-trace message.
725 *
726 * Must pass either the pool or the connection handle so the trace system can
727 * look up the registered callback
728 *
729 * \param[in] is_debug If M_TRUE, #M_SQL_TRACE_DRIVER_DEBUG is used, if M_FALSE, #M_SQL_TRACE_DRIVER_ERROR is used.
730 * \param[in] pool Conditional. If conn is not provided, must be populated. The initialized pool handle.
731 * \param[in] conn Conditional. If pool is not provided, must be populated. The initialized connection handle.
732 * \param[in] err Error code, possibly #M_SQL_ERROR_SUCCESS if not an error but a debug message.
733 * \param[in] msg Message to send to the trace callback
734 */
735M_API void M_sql_driver_trace_message(M_bool is_debug, M_sql_connpool_t *pool, M_sql_conn_t *conn, M_sql_error_t err, const char *msg);
736
737
738#ifdef MSTDLIB_SQL_STATIC_MODULE
739# define M_SQL_API
740#else
741# define M_SQL_API M_DLL_EXPORT
742#endif
743
744
745/*! Use in sql driver source file to create entry point
746 * \param[in] name is the name of the module, a M_sql_driver_t structure
747 * must be defined named M_sql_[name] */
748#define M_SQL_DRIVER(name) \
749 M_SQL_API M_sql_driver_t *M_sql_get_driver_##name(void); \
750 M_sql_driver_t *M_sql_get_driver_##name(void) \
751 { \
752 return &M_sql_##name; \
753 }
754
755/*! @} */
756
757__END_DECLS
758
759#endif /* __M_SQL_DRIVER_H__ */
struct M_buf M_buf_t
Definition: m_buf.h:77
struct M_hash_dict M_hash_dict_t
Definition: m_hash_dict.h:52
void * M_module_handle_t
Definition: m_module.h:52
struct M_sql_connpool M_sql_connpool_t
Definition: m_sql.h:335
M_sql_connstr_type_t type
Definition: m_sql_driver.h:449
M_sql_driver_cb_rewrite_indexname_t cb_rewrite_indexname
Definition: m_sql_driver.h:389
M_sql_driver_cb_queryformat_t cb_queryformat
Definition: m_sql_driver.h:376
M_sql_driver_cb_execute_t cb_execute
Definition: m_sql_driver.h:380
M_sql_driver_cb_queryrowcnt_t cb_queryrowcnt
Definition: m_sql_driver.h:377
M_uint16 port
Definition: m_sql_driver.h:461
M_sql_driver_cb_fetch_t cb_fetch
Definition: m_sql_driver.h:381
M_bool required
Definition: m_sql_driver.h:450
M_uint16 driver_sys_version
Definition: m_sql_driver.h:361
M_sql_driver_cb_createpool_t cb_createpool
Definition: m_sql_driver.h:370
const char * display_name
Definition: m_sql_driver.h:363
const char * name
Definition: m_sql_driver.h:448
M_sql_driver_cb_connect_t cb_connect
Definition: m_sql_driver.h:372
M_sql_driver_cb_prepare_destroy_t cb_prepare_destroy
Definition: m_sql_driver.h:379
M_sql_driver_cb_disconnect_t cb_disconnect
Definition: m_sql_driver.h:375
M_module_handle_t handle
Definition: m_sql_driver.h:390
M_sql_driver_cb_rollback_t cb_rollback
Definition: m_sql_driver.h:383
M_sql_driver_cb_begin_t cb_begin
Definition: m_sql_driver.h:382
M_sql_driver_cb_commit_t cb_commit
Definition: m_sql_driver.h:384
const char * version
Definition: m_sql_driver.h:364
M_sql_driver_cb_connect_runonce_t cb_connect_runonce
Definition: m_sql_driver.h:374
M_sql_driver_cb_datatype_t cb_datatype
Definition: m_sql_driver.h:385
const char * name
Definition: m_sql_driver.h:362
M_sql_driver_cb_append_bitop_t cb_append_bitop
Definition: m_sql_driver.h:388
M_sql_driver_cb_destroypool_t cb_destroypool
Definition: m_sql_driver.h:371
size_t max_len
Definition: m_sql_driver.h:452
M_sql_driver_cb_append_updlock_t cb_append_updlock
Definition: m_sql_driver.h:387
M_sql_driver_cb_destroy_t cb_destroy
Definition: m_sql_driver.h:369
M_sql_driver_cb_createtable_suffix_t cb_createtable_suffix
Definition: m_sql_driver.h:386
M_sql_driver_cb_serverversion_t cb_serverversion
Definition: m_sql_driver.h:373
M_sql_driver_cb_init_t cb_init
Definition: m_sql_driver.h:368
M_sql_driver_cb_flags_t cb_flags
Definition: m_sql_driver.h:367
size_t min_len
Definition: m_sql_driver.h:451
M_sql_driver_cb_prepare_t cb_prepare
Definition: m_sql_driver.h:378
size_t M_sql_driver_stmt_bind_rows(M_sql_stmt_t *stmt)
M_sql_driver_bitop_caps_t
Definition: m_sql_driver.h:702
void(* M_sql_driver_cb_disconnect_t)(M_sql_driver_conn_t *conn)
Definition: m_sql_driver.h:167
const char * M_sql_driver_stmt_bind_get_text(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_bool M_sql_driver_append_bitop(M_sql_driver_bitop_caps_t caps, M_buf_t *query, M_sql_query_bitop_t op, const char *exp1, const char *exp2)
M_sql_error_t(* M_sql_driver_cb_begin_t)(M_sql_conn_t *conn, M_sql_isolation_t isolation, char *error, size_t error_size)
Definition: m_sql_driver.h:254
M_sql_error_t(* M_sql_driver_cb_connect_runonce_t)(M_sql_conn_t *conn, M_sql_driver_connpool_t *dpool, M_bool is_first_in_pool, M_bool is_readonly, char *error, size_t error_size)
Definition: m_sql_driver.h:161
void(* M_sql_driver_cb_destroy_t)(void)
Definition: m_sql_driver.h:97
void(* M_sql_driver_cb_createtable_suffix_t)(M_sql_connpool_t *pool, M_buf_t *query)
Definition: m_sql_driver.h:304
M_bool M_sql_driver_conn_is_readonly(M_sql_conn_t *conn)
size_t M_sql_driver_stmt_get_requested_row_cnt(M_sql_stmt_t *stmt)
M_bool M_sql_driver_conn_in_trans(M_sql_conn_t *conn)
size_t M_sql_driver_conn_get_id(M_sql_conn_t *conn)
size_t(* M_sql_driver_cb_queryrowcnt_t)(M_sql_conn_t *conn, size_t num_params, size_t num_rows)
Definition: m_sql_driver.h:194
size_t M_sql_driver_stmt_bind_get_curr_col_size(M_sql_stmt_t *stmt, size_t row, size_t col)
M_sql_driver_flags_t
Definition: m_sql_driver.h:346
M_bool M_sql_driver_stmt_bind_isnull(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_bool(* M_sql_driver_cb_append_bitop_t)(M_sql_connpool_t *pool, M_buf_t *query, M_sql_query_bitop_t op, const char *exp1, const char *exp2)
Definition: m_sql_driver.h:330
size_t M_sql_driver_stmt_bind_get_text_len(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_bool M_sql_driver_stmt_result_set_col_type(M_sql_stmt_t *stmt, size_t col, M_sql_data_type_t type, size_t max_size)
M_bool M_sql_driver_stmt_bind_get_bool(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_sql_error_t(* M_sql_driver_cb_execute_t)(M_sql_conn_t *conn, M_sql_stmt_t *stmt, size_t *rows_executed, char *error, size_t error_size)
Definition: m_sql_driver.h:230
M_sql_data_type_t M_sql_driver_stmt_bind_get_type(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_sql_conn_state_t
Definition: m_sql_driver.h:466
M_int16 * M_sql_driver_stmt_bind_get_int16_addr(M_sql_stmt_t *stmt, size_t row, size_t idx)
const char * M_sql_driver_conn_get_password(M_sql_conn_t *conn)
const char *(* M_sql_driver_cb_serverversion_t)(M_sql_driver_conn_t *conn)
Definition: m_sql_driver.h:142
void(* M_sql_driver_cb_destroypool_t)(M_sql_driver_connpool_t *dpool)
Definition: m_sql_driver.h:125
M_int32 M_sql_driver_stmt_bind_get_int32(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_sql_conn_state_t M_sql_conn_get_state(M_sql_conn_t *conn)
M_sql_driver_stmt_t * M_sql_driver_stmt_get_stmt(M_sql_stmt_t *stmt)
size_t M_sql_driver_stmt_bind_cnt(M_sql_stmt_t *stmt)
M_sql_connpool_t * M_sql_driver_conn_get_pool(M_sql_conn_t *conn)
M_sql_driver_connpool_t * M_sql_driver_conn_get_dpool(M_sql_conn_t *conn)
M_sql_error_t(* M_sql_driver_cb_fetch_t)(M_sql_conn_t *conn, M_sql_stmt_t *stmt, char *error, size_t error_size)
Definition: m_sql_driver.h:241
const char * M_sql_driver_isolation2str(M_sql_isolation_t type)
M_bool M_sql_driver_stmt_result_set_affected_rows(M_sql_stmt_t *stmt, size_t cnt)
M_bool M_sql_driver_stmt_result_set_col_name(M_sql_stmt_t *stmt, size_t col, const char *name)
M_sql_error_t(* M_sql_driver_cb_rollback_t)(M_sql_conn_t *conn)
Definition: m_sql_driver.h:269
size_t M_sql_driver_stmt_bind_get_binary_len(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_int64 * M_sql_driver_stmt_bind_get_int64_addr(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_sql_error_t M_sql_conn_execute(M_sql_conn_t *conn, M_sql_stmt_t *stmt)
M_int32 * M_sql_driver_stmt_bind_get_int32_addr(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_sql_driver_conn_t * M_sql_driver_conn_get_conn(M_sql_conn_t *conn)
M_sql_data_type_t M_sql_driver_stmt_bind_get_col_type(M_sql_stmt_t *stmt, size_t idx)
struct M_sql_driver_connpool M_sql_driver_connpool_t
Definition: m_sql_driver.h:68
M_sql_isolation_t M_sql_driver_str2isolation(const char *str)
struct M_sql_driver_stmt M_sql_driver_stmt_t
Definition: m_sql_driver.h:80
M_bool(* M_sql_driver_cb_init_t)(char *error, size_t error_size)
Definition: m_sql_driver.h:91
void(* M_sql_driver_cb_append_updlock_t)(M_sql_connpool_t *pool, M_buf_t *query, M_sql_query_updlock_type_t type, const char *table_name)
Definition: m_sql_driver.h:316
size_t M_sql_driver_stmt_bind_get_max_col_size(M_sql_stmt_t *stmt, size_t idx)
M_sql_error_t(* M_sql_driver_cb_prepare_t)(M_sql_driver_stmt_t **driver_stmt, M_sql_conn_t *conn, M_sql_stmt_t *stmt, char *error, size_t error_size)
Definition: m_sql_driver.h:208
M_sql_driver_updlock_caps_t
Definition: m_sql_driver.h:683
void M_sql_driver_append_updlock(M_sql_driver_updlock_caps_t caps, M_buf_t *query, M_sql_query_updlock_type_t type, const char *table_name)
M_sql_error_t(* M_sql_driver_cb_commit_t)(M_sql_conn_t *conn, char *error, size_t error_size)
Definition: m_sql_driver.h:281
const char * M_sql_driver_stmt_get_query(M_sql_stmt_t *stmt)
M_bool(* M_sql_driver_cb_datatype_t)(M_sql_connpool_t *pool, M_buf_t *buf, M_sql_data_type_t type, size_t max_len, M_bool is_cast)
Definition: m_sql_driver.h:294
M_sql_driver_connpool_t * M_sql_driver_pool_get_dpool(M_sql_connpool_t *pool)
struct M_sql_driver_conn M_sql_driver_conn_t
Definition: m_sql_driver.h:74
M_sql_driver_flags_t(* M_sql_driver_cb_flags_t)(M_sql_conn_t *conn)
Definition: m_sql_driver.h:356
const char * M_sql_driver_pool_get_password(M_sql_connpool_t *pool)
const char * M_sql_driver_conn_get_username(M_sql_conn_t *conn)
M_bool M_sql_driver_stmt_result_set_num_cols(M_sql_stmt_t *stmt, size_t cnt)
M_bool M_sql_driver_validate_connstr(const M_hash_dict_t *conndict, const M_sql_connstr_params_t *params, char *error, size_t error_size)
char *(* M_sql_driver_cb_rewrite_indexname_t)(M_sql_connpool_t *pool, const char *index_name)
Definition: m_sql_driver.h:343
const char * M_sql_driver_pool_get_username(M_sql_connpool_t *pool)
void(* M_sql_driver_cb_prepare_destroy_t)(M_sql_driver_stmt_t *stmt)
Definition: m_sql_driver.h:214
M_int16 M_sql_driver_stmt_bind_get_int16(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_sql_error_t(* M_sql_driver_cb_connect_t)(M_sql_driver_conn_t **conn, M_sql_connpool_t *pool, M_bool is_readonly_pool, size_t host_idx, char *error, size_t error_size)
Definition: m_sql_driver.h:136
M_sql_connstr_type_t
Definition: m_sql_driver.h:436
M_buf_t * M_sql_driver_stmt_result_col_start(M_sql_stmt_t *stmt)
char *(* M_sql_driver_cb_queryformat_t)(M_sql_conn_t *conn, const char *query, size_t num_params, size_t num_rows, char *error, size_t error_size)
Definition: m_sql_driver.h:184
struct M_sql_conn M_sql_conn_t
Definition: m_sql_driver.h:62
M_bool(* M_sql_driver_cb_createpool_t)(M_sql_driver_connpool_t **dpool, M_sql_connpool_t *pool, M_bool is_readonly, const M_hash_dict_t *conndict, size_t *num_hosts, char *error, size_t error_size)
Definition: m_sql_driver.h:119
M_int64 M_sql_driver_stmt_bind_get_int64(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_sql_stmt_t * M_sql_conn_execute_simple(M_sql_conn_t *conn, const char *query, M_bool skip_sanity_checks)
void M_sql_driver_trace_message(M_bool is_debug, M_sql_connpool_t *pool, M_sql_conn_t *conn, M_sql_error_t err, const char *msg)
M_bool M_sql_driver_stmt_result_row_finish(M_sql_stmt_t *stmt)
const M_uint8 * M_sql_driver_stmt_bind_get_binary(M_sql_stmt_t *stmt, size_t row, size_t idx)
M_bool * M_sql_driver_stmt_bind_get_bool_addr(M_sql_stmt_t *stmt, size_t row, size_t idx)
char * M_sql_driver_queryformat(const char *query, M_uint32 flags, size_t num_params, size_t num_rows, char *error, size_t error_size)
M_sql_hostport_t * M_sql_driver_parse_hostport(const char *hostport, M_uint16 default_port, size_t *out_len, char *error, size_t error_size)
M_sql_driver_queryformat_flags_t
Definition: m_sql_driver.h:395
@ M_SQL_DRIVER_BITOP_CAP_FUNC
Definition: m_sql_driver.h:704
@ M_SQL_DRIVER_BITOP_CAP_OP_CAST_BIGINT
Definition: m_sql_driver.h:705
@ M_SQL_DRIVER_BITOP_CAP_OP
Definition: m_sql_driver.h:703
@ M_SQL_DRIVER_FLAG_NONE
Definition: m_sql_driver.h:347
@ M_SQL_DRIVER_FLAG_UNIQUEINDEX_NOTNULL_WHERE
Definition: m_sql_driver.h:348
@ M_SQL_CONN_STATE_OK
Definition: m_sql_driver.h:467
@ M_SQL_CONN_STATE_FAILED
Definition: m_sql_driver.h:469
@ M_SQL_CONN_STATE_ROLLBACK
Definition: m_sql_driver.h:468
@ M_SQL_DRIVER_UPDLOCK_CAP_MSSQL
Definition: m_sql_driver.h:686
@ M_SQL_DRIVER_UPDLOCK_CAP_FORUPDATEOF
Definition: m_sql_driver.h:687
@ M_SQL_DRIVER_UPDLOCK_CAP_FORUPDATE
Definition: m_sql_driver.h:685
@ M_SQL_DRIVER_UPDLOCK_CAP_NONE
Definition: m_sql_driver.h:684
@ M_SQL_CONNSTR_TYPE_BOOL
Definition: m_sql_driver.h:437
@ M_SQL_CONNSTR_TYPE_NUM
Definition: m_sql_driver.h:438
@ M_SQL_CONNSTR_TYPE_ALPHANUM
Definition: m_sql_driver.h:440
@ M_SQL_CONNSTR_TYPE_ALPHA
Definition: m_sql_driver.h:439
@ M_SQL_CONNSTR_TYPE_ANY
Definition: m_sql_driver.h:441
@ M_SQL_DRIVER_QUERYFORMAT_TERMINATOR
Definition: m_sql_driver.h:397
@ M_SQL_DRIVER_QUERYFORMAT_ENUMPARAM_COLON
Definition: m_sql_driver.h:400
@ M_SQL_DRIVER_QUERYFORMAT_INSERT_ONCONFLICT_DONOTHING
Definition: m_sql_driver.h:407
@ M_SQL_DRIVER_QUERYFORMAT_MULITVALUEINSERT_CD
Definition: m_sql_driver.h:402
@ M_SQL_DRIVER_QUERYFORMAT_NORMAL
Definition: m_sql_driver.h:396
@ M_SQL_DRIVER_QUERYFORMAT_ENUMPARAM_DOLLAR
Definition: m_sql_driver.h:398
Definition: m_sql_driver.h:447
Definition: m_sql_driver.h:360
Definition: m_sql_driver.h:459
M_sql_error_t
Definition: m_sql.h:190
M_sql_data_type_t
Definition: m_sql.h:256
M_sql_query_bitop_t
Definition: m_sql.h:706
M_sql_query_updlock_type_t
Definition: m_sql.h:623
struct M_sql_stmt M_sql_stmt_t
Definition: m_sql_stmt.h:46
M_sql_isolation_t
Definition: m_sql_trans.h:53