Database connection.
More...
|
typedef struct vtm_sql_con_vt | vtm_sql_con |
|
|
VTM_API int | vtm_sql_set_auto_commit (vtm_sql_con *con, bool commit) |
|
VTM_API int | vtm_sql_commit (vtm_sql_con *con) |
|
VTM_API int | vtm_sql_rollback (vtm_sql_con *con) |
|
VTM_API int | vtm_sql_prepare (vtm_sql_con *con, const char *query, struct vtm_sql_stmt *stmt) |
|
VTM_API int | vtm_sql_execute (vtm_sql_con *con, const char *query) |
|
VTM_API int | vtm_sql_execute_prepared (vtm_sql_con *con, const char *query, vtm_dataset *bind) |
|
VTM_API int | vtm_sql_query (vtm_sql_con *con, const char *query, struct vtm_sql_result *result) |
|
VTM_API int | vtm_sql_query_prepared (vtm_sql_con *con, const char *query, vtm_dataset *bind, struct vtm_sql_result *result) |
|
VTM_API void | vtm_sql_con_free (vtm_sql_con *con) |
|
|
VTM_API const char *const | VTM_SQL_PAR_HOST |
|
VTM_API const char *const | VTM_SQL_PAR_PORT |
|
VTM_API const char *const | VTM_SQL_PAR_USER |
|
VTM_API const char *const | VTM_SQL_PAR_PASSWORD |
|
VTM_API const char *const | VTM_SQL_PAR_DATABASE |
|
VTM_API int vtm_sql_set_auto_commit |
( |
vtm_sql_con * |
con, |
|
|
bool |
commit |
|
) |
| |
Set auto commit option on the connection.
If auto commit is disabled the connection works in transaction mode, where a bunch of related SQL statements can be commited or rollbacked together.
- Parameters
-
con | the connection |
commit | true if auto-commit should be enabled |
- Returns
- VTM_OK if the call succeed
-
VTM_E_SQL_PENDING_RESULT if there is an open resultset from this connection that has not been processed yet
-
VTM_E_SQL_UNKNOWN or VTM_ERROR if an unknown error occured
VTM_API int vtm_sql_commit |
( |
vtm_sql_con * |
con | ) |
|
Execute commit on the given connection.
That makes all changes since the last commit/rollback permanent.
- Parameters
-
- Returns
- VTM_OK if the call succeed
-
VTM_E_SQL_PENDING_RESULT if there is an open resultset from this connection that has not been processed yet
-
VTM_E_SQL_UNKNOWN or VTM_ERROR if an unknown error occured
VTM_API int vtm_sql_rollback |
( |
vtm_sql_con * |
con | ) |
|
Execute rollback on the given connection.
That reverts all pending changes since the last commit/rollback.
- Parameters
-
- Returns
- VTM_OK if the call succeed
-
VTM_E_SQL_PENDING_RESULT if there is an open resultset from this connection that has not been processed yet
-
VTM_E_SQL_UNKNOWN or VTM_ERROR if an unknown error occured
VTM_API int vtm_sql_prepare |
( |
vtm_sql_con * |
con, |
|
|
const char * |
query, |
|
|
struct vtm_sql_stmt * |
stmt |
|
) |
| |
Creates a new prepared statment.
The parameters which should be used by the statement are specified in the given query string with ":<ParameterName>".
- Parameters
-
con | the connection |
query | the query string which is executed by the statement |
stmt | the variable that should hold the initialized statement |
- Returns
- VTM_OK if the prepared statement was successfully created
-
VTM_E_SQL_PENDING_RESULT if there is an open resultset from this connection that has not been processed yet
-
VTM_E_SQL_UNKNOWN or VTM_ERROR if an unknown error occured
VTM_API int vtm_sql_execute |
( |
vtm_sql_con * |
con, |
|
|
const char * |
query |
|
) |
| |
Executes given SQL statement.
- Parameters
-
con | the connection |
query | the SQL statement that should executed |
- Returns
- VTM_OK if the statement was successfully executed
-
VTM_E_SQL_PENDING_RESULT if there is an open resultset from this connection that has not been processed yet
-
VTM_E_SQL_UNKNOWN or VTM_ERROR if an unknown error occured
VTM_API int vtm_sql_execute_prepared |
( |
vtm_sql_con * |
con, |
|
|
const char * |
query, |
|
|
vtm_dataset * |
bind |
|
) |
| |
Convenience method for executing a prepared statement once.
- Parameters
-
con | the connection |
query | the SQL statement containing parameters |
bind | the dataset containing the parameter values |
- Returns
- VTM_OK if the statement was successfully executed
-
VTM_E_SQL_PENDING_RESULT if there is an open resultset from this connection that has not been processed yet
-
VTM_E_SQL_UNKNOWN or VTM_ERROR if an unknown error occured
VTM_API int vtm_sql_query |
( |
vtm_sql_con * |
con, |
|
|
const char * |
query, |
|
|
struct vtm_sql_result * |
result |
|
) |
| |
Executes an SQL statement that returns a result.
- Parameters
-
con | the connection |
query | the SQL query that should executed |
result | the variable that should be initialized with the result set |
- Returns
- VTM_OK if the query was successfully executed
-
VTM_E_SQL_PENDING_RESULT if there is an open resultset from this connection that has not been processed yet
-
VTM_E_SQL_UNKNOWN or VTM_ERROR if an unknown error occured
VTM_API int vtm_sql_query_prepared |
( |
vtm_sql_con * |
con, |
|
|
const char * |
query, |
|
|
vtm_dataset * |
bind, |
|
|
struct vtm_sql_result * |
result |
|
) |
| |
Convenience method for querying a prepared statement once.
- Parameters
-
con | the connection |
query | the SQL statement containing parameters |
bind | the dataset containing the parameter values |
result | the variable that should be initialized with the result set |
- Returns
- VTM_OK if the statement was successfully executed
-
VTM_E_SQL_PENDING_RESULT if there is an open resultset from this connection that has not been processed yet
-
VTM_E_SQL_UNKNOWN or VTM_ERROR if an unknown error occured
VTM_API void vtm_sql_con_free |
( |
vtm_sql_con * |
con | ) |
|
Closes the database connection and releases all associated resources.
After this call the connection pointer is no longer valid.
- Parameters
-
con | the connection that should be released |