Typedefs | Functions | Variables
sql_connection.h File Reference

Database connection. More...

Typedefs

typedef struct vtm_sql_con_vt vtm_sql_con
 

Functions

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)
 

Variables

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
 

Function Documentation

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
conthe connection
committrue 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
conthe connection
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
conthe connection
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
conthe connection
querythe query string which is executed by the statement
stmtthe 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
conthe connection
querythe 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
conthe connection
querythe SQL statement containing parameters
bindthe 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
conthe connection
querythe SQL query that should executed
resultthe 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
conthe connection
querythe SQL statement containing parameters
bindthe dataset containing the parameter values
resultthe 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
conthe connection that should be released