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

Convenience functions. More...

Collaboration diagram for Free Functions:

Namespaces

namespace  nanodbc::detail
 Implementation details, not part of the interface.
 

Classes

struct  nanodbc::driver
 Information on a configured ODBC driver. More...
 
struct  nanodbc::datasource
 A data source name registered with the driver manager. More...
 

Functions

std::list< drivernanodbc::list_drivers ()
 Returns a list of ODBC drivers on your system.
 
std::list< datasourcenanodbc::list_datasources ()
 Returns a list of ODBC data sources on your system.
 
result nanodbc::execute (connection &conn, string const &query, long batch_operations=1, long timeout=0)
 Immediately opens, prepares, and executes the given query directly on the given connection.
 
void nanodbc::just_execute (connection &conn, string const &query, long batch_operations=1, long timeout=0)
 Opens, prepares, and executes query directly without creating result object.
 
template<class Rows , class... Accessors>
void nanodbc::bind_rows (statement &stmt, Rows const &rows, Accessors const &... accessors)
 Binds a range of rows, a parameter at a time.
 
result nanodbc::execute (statement &stmt, long batch_operations=1)
 Execute the previously prepared query now.
 
void nanodbc::just_execute (statement &stmt, long batch_operations=1)
 Execute the previously prepared query now and without creating result object.
 
result nanodbc::transact (statement &stmt, long batch_operations)
 Execute the previously prepared query now.
 
void nanodbc::just_transact (statement &stmt, long batch_operations)
 Execute the previously prepared query now and without creating result object.
 
void nanodbc::prepare (statement &stmt, string const &query, long timeout=0)
 Prepares the given statement to execute on it associated connection.
 

Detailed Description

Convenience functions.

Function Documentation

◆ execute() [1/2]

result nanodbc::execute ( connection conn,
string const &  query,
long  batch_operations = 1,
long  timeout = 0 
)

Immediately opens, prepares, and executes the given query directly on the given connection.

Parameters
connThe connection where the statement will be executed.
queryThe SQL query that will be executed.
batch_operationsNumbers of rows to fetch per rowset.
timeoutThe number in seconds before query timeout. Default is 0 indicating no timeout.
Returns
A result set object.
Attention
You will want to use transactions if you are doing batch operations because it will prevent auto commits from occurring after each individual operation is executed.
See also
open(), prepare(), execute(), result, transaction

◆ just_execute() [1/2]

void nanodbc::just_execute ( connection conn,
string const &  query,
long  batch_operations = 1,
long  timeout = 0 
)

Opens, prepares, and executes query directly without creating result object.

Parameters
connThe connection where the statement will be executed.
queryThe SQL query that will be executed.
batch_operationsRows to fetch per rowset, or number of batch parameters to process.
timeoutThe number in seconds before query timeout. Default is 0 indicating no timeout.
Attention
You will want to use transactions if you are doing batch operations because it will prevent auto commits from occurring after each individual operation is executed.
See also
open(), prepare(), execute(), result, transaction

◆ bind_rows()

template<class Rows , class... Accessors>
void nanodbc::bind_rows ( statement stmt,
Rows const &  rows,
Accessors const &...  accessors 
)

Binds a range of rows, a parameter at a time.

Parameters are bound column-wise, which is what the ODBC drivers expect, from rows held however the caller finds convenient. Each accessor names one parameter, in the order the placeholders appear: either a pointer to a member, or anything callable with a row.

struct person
{
long id;
};
std::vector<person> people = load();
nanodbc::statement stmt(conn);
prepare(stmt, NANODBC_TEXT("insert into people (id, name) values (?, ?)"));
bind_rows(stmt, people, &person::id, &person::name);
execute(stmt, people.size());
Represents a statement on the database.
Definition nanodbc.h:874
void prepare(statement &stmt, string const &query, long timeout=0)
Prepares the given statement to execute on it associated connection.
void bind_rows(statement &stmt, Rows const &rows, Accessors const &... accessors)
Binds a range of rows, a parameter at a time.
Definition nanodbc.h:3225
result execute(connection &conn, string const &query, long batch_operations=1, long timeout=0)
Immediately opens, prepares, and executes the given query directly on the given connection.
unspecified type string
string will be std::u16string or std::32string if NANODBC_ENABLE_UNICODE defined.
Definition nanodbc.h:226
#define NANODBC_TEXT(s)
Creates a string literal of the type corresponding to nanodbc::string.
Definition nanodbc.h:220

An accessor yielding std::optional binds an absent value as null.

The values are copied into the statement, so the rows are free to go out of scope before it is executed.

Parameters
stmtThe prepared statement to bind to.
rowsThe rows to bind, a container with size() whose values the accessors read.
accessorsOne per parameter marker, left to right.
Exceptions
database_error
See also
statement::bind(), statement::bind_strings(), execute()

◆ execute() [2/2]

result nanodbc::execute ( statement stmt,
long  batch_operations = 1 
)

Execute the previously prepared query now.

Parameters
stmtThe prepared statement that will be executed.
batch_operationsRows to fetch per rowset, or the number of batch parameters to process.
Exceptions
database_error
Returns
A result set object.
Attention
You will want to use transactions if you are doing batch operations because it will prevent auto commits from occurring after each individual operation is executed.
See also
open(), prepare(), execute(), result

◆ just_execute() [2/2]

void nanodbc::just_execute ( statement stmt,
long  batch_operations = 1 
)

Execute the previously prepared query now and without creating result object.

Parameters
stmtThe prepared statement that will be executed.
batch_operationsRows to fetch per rowset, or the number of batch parameters to process.
Exceptions
database_error
Attention
You will want to use transactions if you are doing batch operations because it will prevent auto commits from occurring after each individual operation is executed.
See also
open(), prepare(), execute(), result

◆ transact()

result nanodbc::transact ( statement stmt,
long  batch_operations 
)

Execute the previously prepared query now.

Executes within the context of a transaction object, commits directly after execution.

Parameters
stmtThe prepared statement that will be executed in batch.
batch_operationsRows to fetch per rowset, or the number of batch parameters to process.
Exceptions
database_error
Returns
A result set object.
See also
open(), prepare(), execute(), result, transaction

◆ just_transact()

void nanodbc::just_transact ( statement stmt,
long  batch_operations 
)

Execute the previously prepared query now and without creating result object.

Executes within the context of a transaction object, commits directly after execution.

Parameters
stmtThe prepared statement that will be executed in batch.
batch_operationsRows to fetch per rowset, or the number of batch parameters to process.
Exceptions
database_error
See also
open(), prepare(), execute(), result, transaction

◆ prepare()

void nanodbc::prepare ( statement stmt,
string const &  query,
long  timeout = 0 
)

Prepares the given statement to execute on it associated connection.

If the statement is not open throws programming_error.

Parameters
stmtThe prepared statement that will be executed in batch.
queryThe SQL query that will be executed.
timeoutThe number in seconds before query timeout. Default is 0 indicating no timeout.
See also
open()
Exceptions
database_error
programming_error