nanodbc
A small C++ wrapper for the native C ODBC API
Loading...
Searching...
No Matches
Binding parameters

These functions are used to bind values to ODBC parameters. More...

Collaboration diagram for Binding parameters:

Modules

 Binding multiple non-string values
 Binds given values to given parameter placeholder number in the prepared statement.
 
 Binding multiple string values
 Binds given string values to parameter marker in prepared statement.
 

Functions

template<class T >
void nanodbc::statement::bind (short param_index, T const *value, param_direction direction=PARAM_IN)
 Binds given value to given parameter placeholder number in the prepared statement.
 
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.
 

Detailed Description

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.

Function Documentation

◆ bind()

template<class T >
void nanodbc::statement::bind ( short  param_index,
T const *  value,
param_direction  direction = PARAM_IN 
)

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_indexZero-based index of parameter marker (placeholder position).
valueValue to substitute into placeholder.
directionODBC parameter direction.
Exceptions
database_error

◆ 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_indexZero-based index of parameter marker (placeholder position).
batch_sizeThe number of elements being bound.
Exceptions
database_error