|
nanodbc
A small C++ wrapper for the native C ODBC API
|
Represents a statement on the database. More...
#include <nanodbc.h>
Public Types | |
| enum | param_direction { PARAM_IN , PARAM_OUT , PARAM_INOUT , PARAM_RETURN } |
| Provides support for retrieving output/return parameters. More... | |
Public Member Functions | |
| statement () | |
| Creates a new un-prepared statement. | |
| statement (class connection &conn) | |
| Constructs a statement object and associates it to the given connection. | |
| statement (class connection &conn, std::list< attribute > const &attributes) | |
| Constructs a statement object and associates it to the given connection, applying the given ODBC statement attributes. | |
| statement (class connection &conn, string const &query, long timeout=0) | |
| Constructs and prepares a statement using the given connection and query. | |
| statement (const statement &rhs) noexcept | |
| Copy constructor. | |
| statement (statement &&rhs) noexcept | |
| Move constructor. | |
| statement & | operator= (statement rhs) noexcept |
| Assignment. | |
| void | swap (statement &rhs) noexcept |
| Member swap. | |
| ~statement () noexcept | |
| Closes the statement. | |
| void | open (class connection &conn) |
| Creates a statement for the given connection. | |
| bool | open () const noexcept |
| Returns true if connection is open. | |
| bool | connected () const noexcept |
| Returns true if connected to the database. | |
| class connection & | connection () noexcept |
| Returns the associated connection object if any. | |
| const class connection & | connection () const noexcept |
| Returns the associated connection object if any. | |
| void * | native_statement_handle () const noexcept |
| Returns the native ODBC statement handle. | |
| void | close () |
| Closes the statement and frees all associated resources. | |
| void | cancel () |
| Cancels execution of the statement. | |
| void | prepare (class connection &conn, string const &query, long timeout=0) |
| Opens and prepares the given statement to execute on the given connection. | |
| void | prepare (string const &query, long timeout=0) |
| Prepares the given statement to execute its associated connection. | |
| void | timeout (long timeout=0) |
| Sets the number in seconds before query timeout. | |
| class result | execute_direct (class connection &conn, string const &query, long batch_operations=1, long timeout=0) |
| Opens, prepares, and executes the given query directly on the given connection. | |
| class result | execute_direct (class connection &conn, string const &query, batch_ops const &array_sizes, long timeout=0) |
| Opens, prepares, and executes the given query directly on the given connection. | |
| bool | async_prepare (string const &query, void *event_handle, long timeout=0) |
| Prepare the given statement, in asynchronous mode. | |
| void | complete_prepare () |
| Completes a previously initiated asynchronous query preparation. | |
| bool | async_execute_direct (class connection &conn, void *event_handle, string const &query, long batch_operations=1, long timeout=0) |
| Opens, prepares, and executes query directly on the given connection, in async mode. | |
| bool | async_execute (void *event_handle, long batch_operations=1, long timeout=0) |
| Execute the previously prepared query now, in asynchronous mode. | |
| class result | complete_execute (long batch_operations=1) |
| Completes a previously initiated asynchronous query execution, returning the result. | |
| void | enable_async (void *event_handle) |
| undocumented - for internal use only (used from result_impl) | |
| void | disable_async () const |
| undocumented - for internal use only (used from result_impl) | |
| void | just_execute_direct (class connection &conn, string const &query, long batch_operations=1, long timeout=0) |
| Execute the previously prepared query now without constructing result object. | |
| class result | execute (long batch_operations=1, long timeout=0) |
| Execute the previously prepared query now. | |
| void | just_execute (long batch_operations=1, long timeout=0) |
| Execute the previously prepared query now without constructing result object. | |
| class result | procedure_columns (string const &catalog, string const &schema, string const &procedure, string const &column) |
| Returns the input and output paramters of the specified stored procedure. | |
| long | affected_rows () const |
| Returns rows affected by the request or -1 if affected rows is not available. | |
| short | columns () const |
| Returns the number of columns in a result set. | |
| void | reset_parameters () noexcept |
| Resets all currently bound parameters. | |
| short | parameters () const |
| Returns the number of parameters in the statement. | |
| unsigned long | parameter_size (short param_index) const |
| Returns parameter size for indicated parameter placeholder in a prepared statement. | |
| short | parameter_scale (short param_index) const |
| Returns parameter scale for indicated parameter placeholder in a prepared statement. | |
| short | parameter_type (short param_index) const |
| Returns parameter type for indicated parameter placeholder in a prepared statement. | |
| template<class T > | |
| void | bind (short param_index, T const *value, param_direction direction=PARAM_IN) |
| Binds given value to given parameter placeholder number in the prepared statement. | |
| template<class T > | |
| void | bind (short param_index, T const *values, std::size_t batch_size, param_direction direction=PARAM_IN) |
| Binds multiple values. | |
| template<class T > | |
| void | bind (short param_index, T const *values, std::size_t batch_size, T const *null_sentry, param_direction direction=PARAM_IN) |
| Binds multiple values. | |
| template<class T > | |
| void | bind (short param_index, T const *values, std::size_t batch_size, bool const *nulls, param_direction direction=PARAM_IN) |
| Binds multiple values. | |
| void | bind (short param_index, std::vector< std::vector< uint8_t > > const &values, param_direction direction=PARAM_IN) |
| Binds multiple values. | |
| void | bind (short param_index, std::vector< std::vector< uint8_t > > const &values, bool const *nulls, param_direction direction=PARAM_IN) |
| Binds multiple values. | |
| void | bind (short param_index, std::vector< std::vector< uint8_t > > const &values, uint8_t const *null_sentry, param_direction direction=PARAM_IN) |
| Binds multiple values. | |
| template<class T , typename = enable_if_character<T>> | |
| void | bind_strings (short param_index, T const *values, std::size_t value_size, std::size_t batch_size, param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| template<class T , typename = enable_if_string<T>> | |
| void | bind_strings (short param_index, std::vector< T > const &values, param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| template<std::size_t BatchSize, std::size_t ValueSize, class T , typename = enable_if_character<T>> | |
| void | bind_strings (short param_index, T const (&values)[BatchSize][ValueSize], param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| template<class T , typename = enable_if_character<T>> | |
| void | bind_strings (short param_index, T const *values, std::size_t value_size, std::size_t batch_size, T const *null_sentry, param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| template<class T , typename = enable_if_string<T>> | |
| void | bind_strings (short param_index, std::vector< T > const &values, typename T::value_type const *null_sentry, param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| template<std::size_t BatchSize, std::size_t ValueSize, class T , typename = enable_if_character<T>> | |
| void | bind_strings (short param_index, T const (&values)[BatchSize][ValueSize], T const *null_sentry, param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| template<class T , typename = enable_if_character<T>> | |
| void | bind_strings (short param_index, T const *values, std::size_t value_size, std::size_t batch_size, bool const *nulls, param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| template<class T , typename = enable_if_string<T>> | |
| void | bind_strings (short param_index, std::vector< T > const &values, bool const *nulls, param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| template<std::size_t BatchSize, std::size_t ValueSize, class T , typename = enable_if_character<T>> | |
| void | bind_strings (short param_index, T const (&values)[BatchSize][ValueSize], bool const *nulls, param_direction direction=PARAM_IN) |
| Binds multiple string values. | |
| void | bind_null (short param_index, std::size_t batch_size=1) |
| Binds null values to the parameter placeholder number in the prepared statement. | |
| void | describe_parameters (const std::vector< short > &idx, const std::vector< short > &type, const std::vector< unsigned long > &size, const std::vector< short > &scale) |
| Sets descriptions for parameters in the prepared statement. | |
Represents a statement on the database.
Provides support for retrieving output/return parameters.
| nanodbc::statement::statement | ( | ) |
Creates a new un-prepared statement.
|
explicit |
|
explicit |
| nanodbc::statement::statement | ( | class connection & | conn, |
| string const & | query, | ||
| long | timeout = 0 |
||
| ) |
Constructs and prepares a statement using the given connection and query.
| conn | The connection to use. |
| query | The SQL query statement. |
| timeout | The number in seconds before query timeout. Default: 0 meaning no timeout. |
|
noexcept |
Closes the statement.
| void nanodbc::statement::open | ( | class connection & | conn | ) |
Creates a statement for the given connection.
| conn | The connection where the statement will be executed. |
| database_error |
| void nanodbc::statement::cancel | ( | ) |
Cancels execution of the statement.
| database_error |
| void nanodbc::statement::prepare | ( | class connection & | conn, |
| string const & | query, | ||
| long | timeout = 0 |
||
| ) |
Opens and prepares the given statement to execute on the given connection.
| conn | The connection where the statement will be executed. |
| query | The SQL query that will be executed. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| database_error |
| void nanodbc::statement::prepare | ( | string const & | query, |
| long | timeout = 0 |
||
| ) |
Prepares the given statement to execute its associated connection.
| query | The SQL query that will be executed. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| database_error | |
| programming_error |
| void nanodbc::statement::timeout | ( | long | timeout = 0 | ) |
Sets the number in seconds before query timeout.
Default is 0 indicating no timeout.
| database_error |
| class result nanodbc::statement::execute_direct | ( | class connection & | conn, |
| string const & | query, | ||
| long | batch_operations = 1, |
||
| long | timeout = 0 |
||
| ) |
Opens, prepares, and executes the given query directly on the given connection.
| conn | The connection where the statement will be executed. |
| query | The SQL query that will be executed. |
| batch_operations | Numbers of rows to fetch per rowset, or the number of batch parameters to process. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| class result nanodbc::statement::execute_direct | ( | class connection & | conn, |
| string const & | query, | ||
| batch_ops const & | array_sizes, | ||
| long | timeout = 0 |
||
| ) |
Opens, prepares, and executes the given query directly on the given connection.
| conn | The connection where the statement will be executed. |
| query | The SQL query that will be executed. |
| array_sizes | More granular control of rows to fetch per rowset, and the number of batch parameters to process. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| bool nanodbc::statement::async_prepare | ( | string const & | query, |
| void * | event_handle, | ||
| long | timeout = 0 |
||
| ) |
Prepare the given statement, in asynchronous mode.
This method will only be available if nanodbc is built against ODBC headers and library that supports asynchronous mode. Such that the identifiers SQL_ATTR_ASYNC_STMT_EVENT and SQLCompleteAsync are extant. Otherwise this method will be defined, but not implemented.
Asynchronous features can be disabled entirely by defining NANODBC_DISABLE_ASYNC when building nanodbc.
| event_handle | The event handle the caller will wait before calling complete_prepare. |
| query | The SQL query that will be prepared. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| database_error |
| void nanodbc::statement::complete_prepare | ( | ) |
Completes a previously initiated asynchronous query preparation.
This method will only be available if nanodbc is built against ODBC headers and library that supports asynchronous mode. Such that the identifiers SQL_ATTR_ASYNC_STMT_EVENT and SQLCompleteAsync are extant. Otherwise this method will be defined, but not implemented.
Asynchronous features can be disabled entirely by defining NANODBC_DISABLE_ASYNC when building nanodbc.
| database_error |
| bool nanodbc::statement::async_execute_direct | ( | class connection & | conn, |
| void * | event_handle, | ||
| string const & | query, | ||
| long | batch_operations = 1, |
||
| long | timeout = 0 |
||
| ) |
Opens, prepares, and executes query directly on the given connection, in async mode.
This method will only be available if nanodbc is built against ODBC headers and library that supports asynchronous mode. Such that the identifiers SQL_ATTR_ASYNC_STMT_EVENT and SQLCompleteAsync are extant. Otherwise this method will be defined, but not implemented.
Asynchronous features can be disabled entirely by defining NANODBC_DISABLE_ASYNC when building nanodbc.
| conn | The connection where the statement will be executed. |
| event_handle | The event handle the caller will wait before calling complete_execute. |
| query | The SQL query that will be executed. |
| batch_operations | Rows to fetch per rowset or number of batch parameters to process. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| database_error |
| bool nanodbc::statement::async_execute | ( | void * | event_handle, |
| long | batch_operations = 1, |
||
| long | timeout = 0 |
||
| ) |
Execute the previously prepared query now, in asynchronous mode.
This method will only be available if nanodbc is built against ODBC headers and library that supports asynchronous mode. Such that the identifiers SQL_ATTR_ASYNC_STMT_EVENT and SQLCompleteAsync are extant. Otherwise this method will be defined, but not implemented.
Asynchronous features can be disabled entirely by defining NANODBC_DISABLE_ASYNC when building nanodbc.
| event_handle | The event handle the caller will wait before calling complete_execute. |
| batch_operations | Rows to fetch per rowset or number of batch parameters to process. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| database_error |
| class result nanodbc::statement::complete_execute | ( | long | batch_operations = 1 | ) |
Completes a previously initiated asynchronous query execution, returning the result.
This method will only be available if nanodbc is built against ODBC headers and library that supports asynchronous mode. Such that the identifiers SQL_ATTR_ASYNC_STMT_EVENT and SQLCompleteAsync are extant. Otherwise this method will be defined, but not implemented.
Asynchronous features can be disabled entirely by defining NANODBC_DISABLE_ASYNC when building nanodbc.
| database_error |
| batch_operations | Rows to fetch per rowset or number of batch parameters to process. |
| void nanodbc::statement::just_execute_direct | ( | class connection & | conn, |
| string const & | query, | ||
| long | batch_operations = 1, |
||
| long | timeout = 0 |
||
| ) |
Execute the previously prepared query now without constructing result object.
| conn | The connection where the statement will be executed. |
| query | The SQL query that will be executed. |
| batch_operations | Rows to fetch per rowset, or number of batch parameters to process. |
| timeout | Seconds before query timeout. Default is 0 indicating no timeout. |
| database_error |
| class result nanodbc::statement::execute | ( | long | batch_operations = 1, |
| long | timeout = 0 |
||
| ) |
Execute the previously prepared query now.
| batch_operations | Rows to fetch per rowset, or number of batch parameters to process. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| database_error |
| void nanodbc::statement::just_execute | ( | long | batch_operations = 1, |
| long | timeout = 0 |
||
| ) |
Execute the previously prepared query now without constructing result object.
| batch_operations | Rows to fetch per rowset, or number of batch parameters to process. |
| timeout | The number in seconds before query timeout. Default 0 meaning no timeout. |
| database_error |
| class result nanodbc::statement::procedure_columns | ( | string const & | catalog, |
| string const & | schema, | ||
| string const & | procedure, | ||
| string const & | column | ||
| ) |
Returns the input and output paramters of the specified stored procedure.
| catalog | The catalog name of the procedure. |
| schema | Pattern to use for schema names. |
| procedure | The name of the procedure. |
| column | Pattern to use for column names. |
| database_error |
| long nanodbc::statement::affected_rows | ( | ) | const |
Returns rows affected by the request or -1 if affected rows is not available.
| database_error |
| short nanodbc::statement::columns | ( | ) | const |
Returns the number of columns in a result set.
| database_error |
| short nanodbc::statement::parameters | ( | ) | const |
Returns the number of parameters in the statement.
| database_error |
| void nanodbc::statement::describe_parameters | ( | const std::vector< short > & | idx, |
| const std::vector< short > & | type, | ||
| const std::vector< unsigned long > & | size, | ||
| const std::vector< short > & | scale | ||
| ) |
Sets descriptions for parameters in the prepared statement.
If your prepared SQL query has any parameter markers, ? (question mark) placeholders this is how you can describe the SQL type, size and scale for some or all of the parameters, prior to binding any data to the parameters. Calling this method is optional: if a parameter is not described using a call to this method, then during a bind an attempt is made to identify it using a call to the ODBC SQLDescribeParam API handle. Once set, description is re-used for possibly repeated binds execution and only cleared when the statement is cleared / destroyed. Parameter markers are numbered using Zero-based index from left to right.
| idx | Vector of zero-based indices of parameters we are describing. |
| type | Vector of (short integer) types. |
| size | Vector of (unsigned long) sizes. |
| scale | Vector of (short integer) decimal precision / scale. |
| programming_error |