These functions are used to bind values to ODBC parameters.
More...
These functions are used to bind values to ODBC parameters.
- Attention
- When nanodbc is compiled as a library, bind() is only available for the types it is explicitly instantiated for in nanodbc.cpp. Using any other type compiles, because the declaration is visible here, but fails to link. The supported types are: bool, signed char, unsigned char, short, unsigned short, int, unsigned int, long int, unsigned long int, long long, unsigned long long, float, double, std::string::value_type, wide_string::value_type, date, time and timestamp. Binary data is bound through the std::vector<std::vector<std::uint8_t>> overloads, and strings through bind_strings().
-
bool is bound as ODBC's SQL_C_BIT, and only the overloads that carry no null information are available for it. The null_sentry overload takes
T const* and the null flags overload takes bool const*, so for T=bool the two collapse into one signature that neither an explicit instantiation nor a call can choose between. Bind nullable booleans as a wider integral type instead.
◆ bind() [1/2]
Binds given value to given parameter placeholder number in the prepared statement.
If your prepared SQL query has any ? placeholders, this is how you bind values to them. Placeholder numbers count from left to right and are 0-indexed.
It is NOT possible to use these functions for batch operations as number of elements is not specified here.
- Parameters
-
| param_index | Zero-based index of parameter marker (placeholder position). |
| value | Value to substitute into placeholder. |
| direction | ODBC parameter direction. |
- Exceptions
-
◆ bind() [2/2]
template<class T >
| void nanodbc::statement::bind |
( |
short |
param_index, |
|
|
std::optional< T > const & |
value, |
|
|
param_direction |
direction = PARAM_IN |
|
) |
| |
|
inline |
Binds a value that may be absent, an absent one being bound as null.
This is the same as bind() followed by bind_null() for the absent case, written so that the caller need not tell the two apart. A copy of the value is taken, so the optional is free to go out of scope before the statement is executed.
std::optional<int> const age = lookup();
stmt.bind(0, age);
- Parameters
-
| param_index | Zero-based index of parameter marker (placeholder position). |
| value | The value to bind, or nothing to bind null. |
| direction | ODBC parameter direction. |
- Exceptions
-
- See also
- bind(), bind_null()
◆ bind_null()
| void nanodbc::statement::bind_null |
( |
short |
param_index, |
|
|
std::size_t |
batch_size = 1 |
|
) |
| |
Binds null values to the parameter placeholder number in the prepared statement.
If your prepared SQL query has any parameter markers, ? (question mark) placeholders, this is how you bind values to them. Parameter markers are numbered using Zero-based index from left to right.
It is possible to use this function for batch operations.
- Parameters
-
| param_index | Zero-based index of parameter marker (placeholder position). |
| batch_size | The number of elements being bound. |
- Exceptions
-