Mstdlib-1.24.0
|
Data Structures | |
struct | M_sql_driver_t |
struct | M_sql_connstr_params_t |
struct | M_sql_hostport_t |
Macros | |
#define | M_SQL_DRIVER_VERSION 0x0100 |
#define | M_SQL_API M_DLL_EXPORT |
#define | M_SQL_DRIVER(name) |
Typedefs | |
typedef struct M_sql_conn | M_sql_conn_t |
typedef struct M_sql_driver_connpool | M_sql_driver_connpool_t |
typedef struct M_sql_driver_conn | M_sql_driver_conn_t |
typedef struct M_sql_driver_stmt | M_sql_driver_stmt_t |
typedef M_bool(* | M_sql_driver_cb_init_t) (char *error, size_t error_size) |
typedef void(* | M_sql_driver_cb_destroy_t) (void) |
typedef 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) |
typedef void(* | M_sql_driver_cb_destroypool_t) (M_sql_driver_connpool_t *dpool) |
typedef 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) |
typedef const char *(* | M_sql_driver_cb_serverversion_t) (M_sql_driver_conn_t *conn) |
typedef 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) |
typedef void(* | M_sql_driver_cb_disconnect_t) (M_sql_driver_conn_t *conn) |
typedef 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) |
typedef size_t(* | M_sql_driver_cb_queryrowcnt_t) (M_sql_conn_t *conn, size_t num_params, size_t num_rows) |
typedef 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) |
typedef void(* | M_sql_driver_cb_prepare_destroy_t) (M_sql_driver_stmt_t *stmt) |
typedef 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) |
typedef 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) |
typedef 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) |
typedef M_sql_error_t(* | M_sql_driver_cb_rollback_t) (M_sql_conn_t *conn) |
typedef M_sql_error_t(* | M_sql_driver_cb_commit_t) (M_sql_conn_t *conn, char *error, size_t error_size) |
typedef 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) |
typedef void(* | M_sql_driver_cb_createtable_suffix_t) (M_sql_connpool_t *pool, M_buf_t *query) |
typedef 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) |
typedef 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) |
typedef char *(* | M_sql_driver_cb_rewrite_indexname_t) (M_sql_connpool_t *pool, const char *index_name) |
typedef M_sql_driver_flags_t(* | M_sql_driver_cb_flags_t) (M_sql_conn_t *conn) |
SQL Module/Driver definitions and helpers.
These functions are used only by the internal implementation and custom loaded drivers. Typically an integrator would never use these unless they are developing their own custom SQL driver. If so, they would
To gain access to these functions.
struct M_sql_driver_t |
Structure to be implemented by SQL drivers with information about the database in use
Data Fields | ||
---|---|---|
M_uint16 | driver_sys_version |
Driver/Module subsystem version, use M_SQL_DRIVER_VERSION |
const char * | name |
Short name of module |
const char * | display_name |
Display name of module |
const char * | version |
Internal module version |
M_sql_driver_cb_flags_t | cb_flags |
Optional. Callback used to get db flags |
M_sql_driver_cb_init_t | cb_init |
Required. Callback used for module initialization. |
M_sql_driver_cb_destroy_t | cb_destroy |
Required. Callback used for module destruction/unloading. |
M_sql_driver_cb_createpool_t | cb_createpool |
Required. Callback used for pool creation |
M_sql_driver_cb_destroypool_t | cb_destroypool |
Required. Callback used for pool destruction |
M_sql_driver_cb_connect_t | cb_connect |
Required. Callback used for connecting to the db |
M_sql_driver_cb_serverversion_t | cb_serverversion |
Required. Callback used to get the server name/version string |
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. |
M_sql_driver_cb_disconnect_t | cb_disconnect |
Required. Callback used to disconnect from the db |
M_sql_driver_cb_queryformat_t | cb_queryformat |
Required. Callback used for reformatting a query to the sql db requirements |
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) |
M_sql_driver_cb_prepare_t | cb_prepare |
Required. Callback used for preparing a query for execution |
M_sql_driver_cb_prepare_destroy_t | cb_prepare_destroy |
Required. Callback used to destroy the driver-specific prepared statement handle |
M_sql_driver_cb_execute_t | cb_execute |
Required. Callback used for executing a prepared query |
M_sql_driver_cb_fetch_t | cb_fetch |
Required. Callback used to fetch result data/rows from server |
M_sql_driver_cb_begin_t | cb_begin |
Required. Callback used to begin a transaction |
M_sql_driver_cb_rollback_t | cb_rollback |
Required. Callback used to rollback a transaction |
M_sql_driver_cb_commit_t | cb_commit |
Required. Callback used to commit a transaction |
M_sql_driver_cb_datatype_t | cb_datatype |
Required. Callback used to convert to data type for server |
M_sql_driver_cb_createtable_suffix_t | cb_createtable_suffix |
Optional. Callback used to append additional data to the Create Table query string |
M_sql_driver_cb_append_updlock_t | cb_append_updlock |
Optional. Callback used to append row-level locking data |
M_sql_driver_cb_append_bitop_t | cb_append_bitop |
Required. Callback used to append a bit operation |
M_sql_driver_cb_rewrite_indexname_t | cb_rewrite_indexname |
Optional. Callback used to rewrite an index name to comply with DB requirements |
M_module_handle_t | handle |
Handle for loaded driver - must be initialized to NULL in the driver structure |
struct M_sql_connstr_params |
Structure defining possible connection string parameters to be passed to M_sql_driver_validate_connstr() to notify callers of possible typos
Typedef for struct M_sql_connstr_params
Data Fields | ||
---|---|---|
const char * | name |
Parameter name (case-insensitive) |
M_sql_connstr_type_t | type |
Data type of parameter |
M_bool | required |
Whether or not the parameter is required |
size_t | min_len |
Minimum length of parameter when present |
size_t | max_len |
Maximum length of parameter when present |
struct M_sql_hostport_t |
Host/port used with M_sql_driver_parse_hostport()
Data Fields | ||
---|---|---|
char | host[256] | |
M_uint16 | port |
#define M_SQL_DRIVER_VERSION 0x0100 |
Current subsystem versioning for module compatibility tracking
#define M_SQL_API M_DLL_EXPORT |
#define M_SQL_DRIVER | ( | name | ) |
Use in sql driver source file to create entry point
[in] | name | is the name of the module, a M_sql_driver_t structure must be defined named M_sql_[name] |
typedef struct M_sql_conn M_sql_conn_t |
Private connection object
typedef struct M_sql_driver_connpool M_sql_driver_connpool_t |
Driver-defined private storage for connection pool (typedef)
typedef struct M_sql_driver_conn M_sql_driver_conn_t |
Driver-defined private storage for connection object (typedef)
typedef struct M_sql_driver_stmt M_sql_driver_stmt_t |
Driver-defined private storage for a statement handle (typedef)
typedef M_bool(* M_sql_driver_cb_init_t) (char *error, size_t error_size) |
Callback called when the module is loaded. If there is any global environment that needs to be set up, it should be called here. This is guaranteed to only be called once.
[out] | error | User-supplied buffer to hold an error message |
[in] | error_size | Size of user-supplied error buffer. |
typedef void(* M_sql_driver_cb_destroy_t) (void) |
Callback called when the module is unloaded. If there is any global environment that needs to be destroyed, it should be called here. This is guaranteed to only be called once and only after a successful M_sql_driver_cb_init_t.
typedef 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) |
Callback called when a pool is created or updated with a read-only pool. A dictionary of configuration is passed for the connection pool type (primary vs readonly).
Any parameters needed should be saved into the private handle returned. The dictionaries passed in should be strictly validated using, at a minimum, M_sql_driver_validate_connstr().
[in,out] | dpool | Driver-specific pool handle. Should be initailized if passed in as NULL. Currently the only time that occurs is when is_readonly is M_FALSE. Only a single driver-specific pool is created for all pool types (primary, readonly), so if an initialized object is passed in, the additional configuration data needs to be appended to the current object. |
[in] | pool | Partially initialized pool, mostly used for getting other metadata for verification (e.g. username/password) |
[in] | is_readonly | M_TRUE if the pool being initialized is readonly, M_FALSE if primary. |
[in] | conndict | Configuration dictionary of parameters |
[out] | num_hosts | The number of hosts contained within the configuration for load balancing or failover purposes. |
[out] | error | User-supplied buffer to output an error message. |
[in] | error_size | Size of user-supplied error buffer. |
typedef void(* M_sql_driver_cb_destroypool_t) (M_sql_driver_connpool_t *dpool) |
Callback called when the pool is destroyed to free the driver-specific pool object
[in] | dpool | Pool object to be destroyed |
typedef 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) |
Callback called to initialize a new connection to the database.
[out] | conn | Initialized private connection object is returned on success. |
[in] | pool | Pool handle, use M_sql_driver_pool_get_dpool() to get driver-specific pool handle. |
[in] | is_readonly_pool | M_TRUE if the connection references a read-only pool, or M_FALSE if the primary pool. |
[in] | host_idx | Host index to use (if multiple hosts configured and returned by M_sql_driver_cb_createpool_t), 0 based. |
[out] | error | User-supplied buffer to output an error message. |
[in] | error_size | Size of user-supplied error buffer. |
typedef const char *(* M_sql_driver_cb_serverversion_t) (M_sql_driver_conn_t *conn) |
Callback called to get the server version string/information
[in] | conn | Private connection object. |
typedef 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) |
Callback called after each connection is successfully established. The is_first_in_pool can be used to key off of to ensure if the action only needs to be performed once for the lifetime of the pool after connectivity is established, it can be done there.
Examples of use for this callback include setting SQLite journal mode, performing an SQLite analyze or integrity check. For other databases, this may be where custom store procedures are created, or default transaction isolation levels are set.
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
[in] | dpool | Driver-specific pool handle returned from M_sql_driver_cb_createpool_t |
[in] | is_first_in_pool | M_TRUE if first connection in a pool to be established, M_FALSE if secondary connection. |
[in] | is_readonly | M_TRUE if this is referencing the readonly pool, M_FALSE if the normal pool |
[out] | error | User-supplied buffer to output an error message. |
[in] | error_size | Size of user-supplied error buffer. |
typedef void(* M_sql_driver_cb_disconnect_t) (M_sql_driver_conn_t *conn) |
Callback called to disconnect and destroy all metadata associated with a connection.
[in] | conn | Private driver-specific connection handle to be disconnected and destroyed |
typedef 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) |
Rewrite the user-provided query string to one more easily consumed by the database backend.
It is suggested implementors use M_sql_driver_queryformat() if possible instead of writing this from scratch.
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
[in] | query | User-provided query string |
[in] | num_params | Number of bound parameters (per row) |
[in] | num_rows | For insert statements, number of rows of bound parameters |
[in] | error | User-supplied error message buffer |
[in] | error_size | Size of user-supplied error message buffer |
typedef size_t(* M_sql_driver_cb_queryrowcnt_t) (M_sql_conn_t *conn, size_t num_params, size_t num_rows) |
Return number of rows that will be worked on for the current execution.
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
[in] | num_params | Number of bound parameters (per row) |
[in] | num_rows | For insert statements, number of rows of bound parameters |
typedef 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) |
Prepare the provided query for execution.
[in,out] | driver_stmt | Driver-specific statement handle. If executing based on a cached prepared statement handle, may pass in existing handle. Handle used will always be returned (may or may not be identical to passed in handle) |
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
[in] | stmt | Statement handle containing all the details necessary for preparation |
[in] | error | User-supplied error message buffer |
[in] | error_size | Size of user-supplied error message buffer |
typedef void(* M_sql_driver_cb_prepare_destroy_t) (M_sql_driver_stmt_t *stmt) |
Destroy the driver-specific prepared statement handle.
[in] | stmt | Driver-specific statement handle to be destroyed. |
typedef 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) |
Execute the query.
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
[in] | stmt | Driver-specific statement handle to be executed as returned by M_sql_driver_cb_prepare_t |
[out] | rows_executed | For drivers that support multiple rows being inserted in a single query, this is how many bind parameter rows were actually inserted by the query. This value may be up to M_sql_driver_stmt_bind_rows() in size. Execute will be called in a loop if not all rows were executed in a single query until complete (with each iteration decrementing the visible M_sql_driver_stmt_bind_rows()). |
[in] | error | User-supplied error message buffer |
[in] | error_size | Size of user-supplied error message buffer |
typedef 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) |
Fetch rows from server
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
[in] | stmt | System statement object, use M_sql_driver_stmt_get_stmt() to fetch driver-specific statement handle. |
[in] | error | User-supplied error message buffer |
[in] | error_size | Size of user-supplied error message buffer |
typedef 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) |
Begin a transaction on the server with the specified isolation level.
If the isolation level is not supported by the server, the closet match should be chosen.
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
[in] | isolation | Requested isolation level |
[out] | error | User-supplied error message buffer |
[in] | error_size | Size of user-supplied error message buffer |
typedef M_sql_error_t(* M_sql_driver_cb_rollback_t) (M_sql_conn_t *conn) |
Rollback a transaction.
The connection object should retain enough metadata to know if there is a current open transaction or not, so that if the transaction was already implicitly closed by a failed previous request, this should be a no-op.
If the rollback fails when it is expected to succeed, the driver should probably return a code to indicate a critical connectivity failure has occurred to kill the connection.
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
typedef M_sql_error_t(* M_sql_driver_cb_commit_t) (M_sql_conn_t *conn, char *error, size_t error_size) |
Commit a transaction.
If a commit fails, the transaction must be automatically rolled back by the driver.
[in] | conn | Initialized connection object, use M_sql_driver_conn_get_conn() to get driver-specific private connection handle. |
[out] | error | User-supplied error message buffer |
[in] | error_size | Size of user-supplied error message buffer |
typedef 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) |
Output the SQL-driver specific data type to the supplied buffer based on the input type and maximum length.
[in] | pool | Pointer to connection pool object |
[in,out] | buf | Buffer to write sql-server-specific data type into. |
[in] | type | mstdlib sql data type |
[in] | max_len | Maximum length of data type. Meaningful for Text and Binary types only, or use 0 for maximum supported server size. |
[in] | is_cast | Used to convert to data type for server. |
typedef void(* M_sql_driver_cb_createtable_suffix_t) (M_sql_connpool_t *pool, M_buf_t *query) |
Append an SQL-driver specific suffix to the end of the provided CREATE TABLE query.
Some servers like MySQL append things like " ENGINE=InnoDB CHARSET=utf8"
[in] | pool | SQL Server pool, use M_sql_driver_pool_get_dpool() to get driver-specific pool metadata. Create Table is always executed against the primary subpool. |
[in,out] | query | Query string to append suffix |
typedef 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) |
Output the SQL-driver-specific update lock as needed.
See M_sql_query_append_updlock() for more information.
[in] | pool | Pointer to connection pool object |
[in,out] | query | Buffer to write sql-server-specific lock information into. |
[in] | type | mstdlib sql updlock type |
[in] | table_name | Table name for "FOR UPDATE OF" style locks |
typedef 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) |
Output the SQL-driver-specific bit operation formatted as needed.
See M_sql_query_append_bitop() for more information.
[in] | pool | Pointer to connection pool object |
[in,out] | query | Buffer to write sql-server-specific bitop into |
[in] | op | Bitwise operation to perform. |
[in] | exp1 | Left-hand side of SQL expression. |
[in] | exp2 | Right-hande size of SQL expression. |
typedef char *(* M_sql_driver_cb_rewrite_indexname_t) (M_sql_connpool_t *pool, const char *index_name) |
Rewrite index identifier name to comply with database limitations.
For instance, Oracle versions prior to 12c R2 has a limitation of 30 characters for identifiers. We need to rewrite the index name if the database version matches.
[in] | pool | Pointer to connection pool object |
[in] | index_name | Desired index name |
typedef M_sql_driver_flags_t(* M_sql_driver_cb_flags_t) (M_sql_conn_t *conn) |
Fetch current flags from driver for connection based
[in] | conn | Initialized connection object. |
enum M_sql_driver_flags_t |
Flags for the helper query string format rewrite function M_sql_driver_queryformat()
enum M_sql_connstr_type_t |
enum M_sql_conn_state_t |
Capabilities driver can use for M_sql_driver_append_updlock() helper
Bit Operations capabilities/type used by SQL server
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 | ||
) |
Rewrite the user-provided query string to one more easily consumed by the database backend based on a series of flags.
This is a helper function to reduce code duplication in database implementations and is exclusively called by the drivers. If the implementation here is insufficient for the requirements of the SQL server, then it is up to the driver to implement their own routine
[in] | query | User-provided query string |
[in] | flags | Bitmap of M_sql_driver_queryformat_flags_t Flags controlling behavior of processor |
[in] | num_params | Number of bound parameters (per row) |
[in] | num_rows | For insert statements, number of rows of bound parameters |
[in] | error | User-supplied error message buffer |
[in] | error_size | Size of user-supplied error message buffer |
M_sql_conn_state_t M_sql_conn_get_state | ( | M_sql_conn_t * | conn | ) |
Get the current connection state.
[in] | conn | Connection acquired with M_sql_connpool_acquireconn() |
M_sql_error_t M_sql_conn_execute | ( | M_sql_conn_t * | conn, |
M_sql_stmt_t * | stmt | ||
) |
Base helper used to execute a statement on a connection handle.
This helper is called by M_sql_stmt_execute() and M_sql_trans_execute()
[in] | conn | Connection acquired with M_sql_connpool_acquireconn() |
[in] | stmt | Prepared statement object to be executed |
M_sql_stmt_t * M_sql_conn_execute_simple | ( | M_sql_conn_t * | conn, |
const char * | query, | ||
M_bool | skip_sanity_checks | ||
) |
Base helper used to execute a simple query (no bound parameters) on a connection handle.
This internally generates a statement handle and destroys it upon completion.
[in] | conn | Connection acquired with M_sql_connpool_acquireconn() |
[in] | query | Direct query to be executed. |
[in] | skip_sanity_checks | Skip sanity checks that may otherwise fail. Usually used for injecting a stored procedure at db init. |
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 | ||
) |
Helper for SQL drivers to validate the connection strings provided.
[in] | conndict | Dictionary of key/value pairs passed to driver |
[in] | params | NULL-terminated structure of parameters to validate. |
[out] | error | User-supplied error buffer to output error message. |
[in] | error_size | Size of user-supplied error buffer. |
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_conn_t * M_sql_driver_conn_get_conn | ( | M_sql_conn_t * | conn | ) |
Retrieve a handle to the driver-specific connection object.
[in] | conn | Connection acquired with M_sql_connpool_acquireconn() |
M_sql_connpool_t * M_sql_driver_conn_get_pool | ( | M_sql_conn_t * | conn | ) |
const char * M_sql_driver_pool_get_username | ( | M_sql_connpool_t * | pool | ) |
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 | ) |
const char * M_sql_driver_conn_get_password | ( | M_sql_conn_t * | conn | ) |
M_sql_driver_connpool_t * M_sql_driver_pool_get_dpool | ( | M_sql_connpool_t * | pool | ) |
M_sql_driver_connpool_t * M_sql_driver_conn_get_dpool | ( | M_sql_conn_t * | conn | ) |
M_bool M_sql_driver_conn_is_readonly | ( | M_sql_conn_t * | conn | ) |
M_bool M_sql_driver_conn_in_trans | ( | M_sql_conn_t * | conn | ) |
Return whether or not the connection is used within an SQL transaction, or simply a single standalone query.
[in] | conn | Initialized M_sql_conn_t |
size_t M_sql_driver_conn_get_id | ( | M_sql_conn_t * | conn | ) |
const char * M_sql_driver_stmt_get_query | ( | M_sql_stmt_t * | stmt | ) |
M_sql_driver_stmt_t * M_sql_driver_stmt_get_stmt | ( | M_sql_stmt_t * | stmt | ) |
size_t M_sql_driver_stmt_bind_rows | ( | M_sql_stmt_t * | stmt | ) |
Retrieve remaining unprocessed row count.
Rows returned, and rows passed in may not accurately reflect the number of rows of parameters actually bound. Some SQL servers do not support multiple rows being inserted in a single query, or may have a limit on how many rows can be inserted at once ... so this is the current 'view' that adjusts for rows that have already been processed so the sql driver doesn't have to track it
[in] | stmt | Initialized statement handle |
size_t M_sql_driver_stmt_bind_cnt | ( | M_sql_stmt_t * | stmt | ) |
Retrieve column count per row, or if a single row or a query that does not support multiple rows (e.g. select), the entire number of parameters bound.
This is NOT the number of bound params for multi-row binding, this is just the number of columns in a single row.
[in] | stmt | Initialized statement handle |
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_data_type_t M_sql_driver_stmt_bind_get_col_type | ( | M_sql_stmt_t * | stmt, |
size_t | idx | ||
) |
Some columns with multiple rows might have a NULL data type bound with the wrong type, this searches for the "real" datatype, first non-null
size_t M_sql_driver_stmt_bind_get_max_col_size | ( | M_sql_stmt_t * | stmt, |
size_t | idx | ||
) |
Get the maximum size of a column if there are multiple rows bound, taking into account things like integer sizes
size_t M_sql_driver_stmt_bind_get_curr_col_size | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | col | ||
) |
Get the current size of the row/column in bytes, taking into account things like integer sizes
size_t M_sql_driver_stmt_get_requested_row_cnt | ( | M_sql_stmt_t * | stmt | ) |
Get the requested row count as requested by the user by M_sql_stmt_set_max_fetch_rows().
This value can be used to set a Prefetch Row setting for receiving rows from the server as an optimization. If a value of 0 is returned, this means the customer did not request partial fetching (user wants all rows), so the server might want to choose an internal default size.
[in] | stmt | Initialized statement handle |
M_bool * M_sql_driver_stmt_bind_get_bool_addr | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
M_int16 * M_sql_driver_stmt_bind_get_int16_addr | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
M_int32 * M_sql_driver_stmt_bind_get_int32_addr | ( | 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_bool M_sql_driver_stmt_bind_get_bool | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
M_int16 M_sql_driver_stmt_bind_get_int16 | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
M_int32 M_sql_driver_stmt_bind_get_int32 | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
M_int64 M_sql_driver_stmt_bind_get_int64 | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
M_bool M_sql_driver_stmt_bind_isnull | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
const char * M_sql_driver_stmt_bind_get_text | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
size_t M_sql_driver_stmt_bind_get_text_len | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
const M_uint8 * M_sql_driver_stmt_bind_get_binary | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
size_t M_sql_driver_stmt_bind_get_binary_len | ( | M_sql_stmt_t * | stmt, |
size_t | row, | ||
size_t | idx | ||
) |
M_bool M_sql_driver_stmt_result_set_affected_rows | ( | M_sql_stmt_t * | stmt, |
size_t | cnt | ||
) |
Set the number of affected rows from things like UPDATE or DELETE
[in] | stmt | Statement handle |
[in] | cnt | Count to set |
M_bool M_sql_driver_stmt_result_set_num_cols | ( | M_sql_stmt_t * | stmt, |
size_t | cnt | ||
) |
Set the column count for the row headers
[in] | stmt | Statement handle |
[in] | cnt | Count to set |
M_bool M_sql_driver_stmt_result_set_col_name | ( | M_sql_stmt_t * | stmt, |
size_t | col, | ||
const char * | name | ||
) |
Sets the column header name for the specified column
Must only be called after M_sql_driver_stmt_result_set_num_cols()
[in] | stmt | Statement handle |
[in] | col | Column to modify |
[in] | name | Name to set |
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 | ||
) |
Sets the column header name for the specified column
Must only be called after M_sql_driver_stmt_result_set_num_cols()
[in] | stmt | Statement handle |
[in] | col | Column to modify |
[in] | type | Column type to set |
[in] | max_size | Maximum size of column (for text or binary data), if available. 0 otherwise. |
M_buf_t * M_sql_driver_stmt_result_col_start | ( | M_sql_stmt_t * | stmt | ) |
Start a new data column, returning writable buffer to hold column data.
The data written to the buffer is the Text or Binary version of the data.
The text version is also used for Integer and Boolean values. If the column is NULL, do not write any data, not even a NULL terminator.
Must only be called after M_sql_driver_stmt_result_set_num_cols(), and highly recommended to have previously called M_sql_driver_stmt_result_set_col_name() and M_sql_driver_stmt_result_set_col_type().
Binary data can only be written if M_sql_driver_stmt_result_set_col_type() is set to M_SQL_DATA_TYPE_BINARY.
[in] | stmt | Statement handle |
M_bool M_sql_driver_stmt_result_row_finish | ( | M_sql_stmt_t * | stmt | ) |
Finish a row worth of data.
This is required to be called after all the columns for a row are written using M_sql_driver_stmt_result_col_start().
[in] | stmt | Statement handle |
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 | ||
) |
Helper for drivers to implement M_sql_driver_cb_append_updlock_t
[in] | caps | Capabilities of SQL server |
[in,out] | query | Buffer to write sql-server-specific lock information into. |
[in] | type | mstdlib sql updlock type |
[in] | table_name | Table name for M_SQL_DRIVER_UPDLOCK_CAP_FORUPDATEOF |
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 | ||
) |
Helper for drivers to implement M_sql_driver_cb_append_bitop_t
[in] | caps | Capabilities of SQL server |
[in,out] | query | Buffer to write sql-server-specific bitop into |
[in] | op | Bitwise operation to perform. |
[in] | exp1 | Left-hand side of SQL expression. |
[in] | exp2 | Right-hande size of SQL expression. |
M_sql_isolation_t M_sql_driver_str2isolation | ( | const char * | str | ) |
const char * M_sql_driver_isolation2str | ( | M_sql_isolation_t | type | ) |
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 | ||
) |
Generate a driver-trace message.
Must pass either the pool or the connection handle so the trace system can look up the registered callback
[in] | is_debug | If M_TRUE, M_SQL_TRACE_DRIVER_DEBUG is used, if M_FALSE, M_SQL_TRACE_DRIVER_ERROR is used. |
[in] | pool | Conditional. If conn is not provided, must be populated. The initialized pool handle. |
[in] | conn | Conditional. If pool is not provided, must be populated. The initialized connection handle. |
[in] | err | Error code, possibly M_SQL_ERROR_SUCCESS if not an error but a debug message. |
[in] | msg | Message to send to the trace callback |