Mstdlib-1.24.0
SQL Error handling functions

Enumerations

enum  M_sql_error_t {
  M_SQL_ERROR_SUCCESS = 0 ,
  M_SQL_ERROR_SUCCESS_ROW = 1 ,
  M_SQL_ERROR_CONN_NODRIVER = 100 ,
  M_SQL_ERROR_CONN_DRIVERLOAD = 101 ,
  M_SQL_ERROR_CONN_DRIVERVER = 102 ,
  M_SQL_ERROR_CONN_PARAMS = 103 ,
  M_SQL_ERROR_CONN_FAILED = 104 ,
  M_SQL_ERROR_CONN_BADAUTH = 105 ,
  M_SQL_ERROR_CONN_LOST = 106 ,
  M_SQL_ERROR_PREPARE_INVALID = 200 ,
  M_SQL_ERROR_PREPARE_STRNOTBOUND = 201 ,
  M_SQL_ERROR_PREPARE_NOMULITQUERY = 202 ,
  M_SQL_ERROR_QUERY_NOTPREPARED = 300 ,
  M_SQL_ERROR_QUERY_WRONGNUMPARAMS = 301 ,
  M_SQL_ERROR_QUERY_PREPARE = 302 ,
  M_SQL_ERROR_QUERY_DEADLOCK = 400 ,
  M_SQL_ERROR_QUERY_CONSTRAINT = 410 ,
  M_SQL_ERROR_QUERY_FAILURE = 499 ,
  M_SQL_ERROR_INUSE = 500 ,
  M_SQL_ERROR_INVALID_USE = 600 ,
  M_SQL_ERROR_INVALID_TYPE = 601 ,
  M_SQL_ERROR_USER_SUCCESS = 700 ,
  M_SQL_ERROR_USER_BYPASS = 703 ,
  M_SQL_ERROR_USER_RETRY = 701 ,
  M_SQL_ERROR_USER_FAILURE = 702 ,
  M_SQL_ERROR_UNSET = 999
}
 
enum  M_sql_data_type_t {
  M_SQL_DATA_TYPE_UNKNOWN = 0 ,
  M_SQL_DATA_TYPE_BOOL = 1 ,
  M_SQL_DATA_TYPE_INT16 = 2 ,
  M_SQL_DATA_TYPE_INT32 = 3 ,
  M_SQL_DATA_TYPE_INT64 = 4 ,
  M_SQL_DATA_TYPE_TEXT = 5 ,
  M_SQL_DATA_TYPE_BINARY = 6
}
 

Functions

const char * M_sql_error_string (M_sql_error_t err)
 
M_bool M_sql_error_is_error (M_sql_error_t err)
 
M_bool M_sql_error_is_disconnect (M_sql_error_t err)
 
M_bool M_sql_error_is_rollback (M_sql_error_t err)
 
M_bool M_sql_error_is_fatal (M_sql_error_t err)
 

Detailed Description

SQL Error handling

Enumeration Type Documentation

◆ M_sql_error_t

Possible error conditions

Enumerator
M_SQL_ERROR_SUCCESS 

No error, success. If returned by M_sql_stmt_fetch(), there are guaranteed to not be any rows in the result set. However, for an M_sql_stmt_execute() or M_sql_trans_execute() if M_sql_stmt_set_max_fetch_rows() was not set, there may be rows available.

M_SQL_ERROR_SUCCESS_ROW 

No error, success, rows may be available to be fetched

M_SQL_ERROR_CONN_NODRIVER 

Driver not found for specified driver name.

M_SQL_ERROR_CONN_DRIVERLOAD 

Failed to dynamically load driver module.

M_SQL_ERROR_CONN_DRIVERVER 

Driver version invalid

M_SQL_ERROR_CONN_PARAMS 

Connection string parameter validation failed

M_SQL_ERROR_CONN_FAILED 

Failed to establish connection to server.

M_SQL_ERROR_CONN_BADAUTH 

Failed to authenticate against server.

M_SQL_ERROR_CONN_LOST 

Connection to server has been lost (remote disconnect).

M_SQL_ERROR_PREPARE_INVALID 

Invalid query format

M_SQL_ERROR_PREPARE_STRNOTBOUND 

A string was detected in the query that was not bound

M_SQL_ERROR_PREPARE_NOMULITQUERY 

Multiple requests in a single query are not allowed

M_SQL_ERROR_QUERY_NOTPREPARED 

Can't execute query as statement hasn't been prepared

M_SQL_ERROR_QUERY_WRONGNUMPARAMS 

Wrong number of bound parameters provided for query

M_SQL_ERROR_QUERY_PREPARE 

DB Driver failed to prepare the query for execution

M_SQL_ERROR_QUERY_DEADLOCK 

Deadlock (must rollback), cannot continue.

M_SQL_ERROR_QUERY_CONSTRAINT 

Constraint failed (e.g. Unique key or primary key conflict)

M_SQL_ERROR_QUERY_FAILURE 

Failure (uncategorized)

M_SQL_ERROR_INUSE 

Resource in use, invalid action

M_SQL_ERROR_INVALID_USE 

Invalid use

M_SQL_ERROR_INVALID_TYPE 

Invalid Data Type for conversion

M_SQL_ERROR_USER_SUCCESS 

Return code a User can generate in M_sql_trans_process() to Indicate the operation is complete and the system can commit any pending data. This is equivalent to M_SQL_ERROR_SUCCESS but can be used in its place if a user needs to have the ability to differentiate how M_sql_trans_process() returned success.

M_SQL_ERROR_USER_BYPASS 

Return code a User can generate in M_sql_trans_process() to indicate the operation should be bypassed. This can be used to differentiate a traditional tristate error message. Otherwise this is classified as success.

M_SQL_ERROR_USER_RETRY 

Return code a User can generate in M_sql_trans_process() to request the system to rollback and retry the entire sequence of events. This is equivalent to M_SQL_ERROR_QUERY_DEADLOCK but more accurately indicates the failure was due to user-logic rather than a condition triggered internally to the SQL system

M_SQL_ERROR_USER_FAILURE 

Return code a User can generate in M_sql_trans_process() to request the system to rollback and return the error to the caller. This is equivalent to M_SQL_ERROR_QUERY_FAILURE but more accurately indicates the failure was due to user-logic rather than a condition triggered internally to the SQL system

M_SQL_ERROR_UNSET 

Error message not set. Internal use only.

◆ M_sql_data_type_t

Possible SQL data types

Enumerator
M_SQL_DATA_TYPE_UNKNOWN 

Not Known, not yet set, most likely an error

M_SQL_DATA_TYPE_BOOL 

Implemented as an 8bit integer

M_SQL_DATA_TYPE_INT16 

16bit signed integer

M_SQL_DATA_TYPE_INT32 

32bit signed integer

M_SQL_DATA_TYPE_INT64 

64bit signed integer

M_SQL_DATA_TYPE_TEXT 

Textual data type such as VARCHAR or TEXT, with possible length

M_SQL_DATA_TYPE_BINARY 

Binary data type such as BLOB or BINARY, with possible length

Function Documentation

◆ M_sql_error_string()

const char * M_sql_error_string ( M_sql_error_t  err)

Retrieve generic error string associated with error code.

Often the error message returned by the calling function or M_sql_stmt_get_error_string() is more useful for human display purposes.

Parameters
[in]errError to evaluate
Returns
string representation of error message.

◆ M_sql_error_is_error()

M_bool M_sql_error_is_error ( M_sql_error_t  err)

Returns if error code is a failure or not.

Currently this returns true if the error condition is any error other than M_SQL_ERROR_SUCCESS or M_SQL_ERROR_SUCCESS_ROW.

Parameters
[in]errError to evaluate
Returns
M_TRUE if error, M_FALSE if not.

◆ M_sql_error_is_disconnect()

M_bool M_sql_error_is_disconnect ( M_sql_error_t  err)

Returns if the error code is due to a fatal communications error. If this occurs, the connection will be automatically destroyed and next use will try to establish a new connection

Parameters
[in]errError to evaluate.
Returns
M_TRUE if connectivity failure, M_FALSE if not.

◆ M_sql_error_is_rollback()

M_bool M_sql_error_is_rollback ( M_sql_error_t  err)

Returns if the error code represents a rollback condition.

There may be multiple types of failures that are rollback conditions such as unexpected disconnects from the database, deadlocks, and consistency failures. This function checks for all known conditions where a rollback should be performed.

Parameters
[in]errError to evaluate.
Returns
M_TRUE if rollback condition, M_FALSE if not.

◆ M_sql_error_is_fatal()

M_bool M_sql_error_is_fatal ( M_sql_error_t  err)

Returns if the error code represents a fatal error returned from the server that is unlikely to succeed if simply re-attempted. Often this is the result of a poorly formed query that can't be parsed or prepared.

Currently this is equivelent to:

M_bool M_sql_error_is_rollback(M_sql_error_t err)
M_bool M_sql_error_is_disconnect(M_sql_error_t err)
M_bool M_sql_error_is_error(M_sql_error_t err)
Parameters
[in]errError to evaluate.
Returns
M_TRUE if fatal error, M_FALSE if not.