SQL connection virtual class. More...
#include <connection.hpp>
Public Member Functions | |
Connection () | |
Connection (const Connection &)=delete | |
virtual | ~Connection () noexcept |
void | startTransaction () |
void | begin () |
void | commit () |
void | rollback () |
void | release () noexcept |
PreparedStatement & | prepareStatement (const std::string &query) |
ResultSet * | query (const std::string &query) |
void | queryMapRow (const std::string &sqlQuery, std::function< void(ResultSet &)> rowMapper) |
void | queryExtract (const std::string &sqlQuery, std::function< void(ResultSet &)> resExtractor) |
template<typename T, typename... Q> | |
ResultSet * | query (const std::string &query, const T &value, const Q &... values) |
template<typename T, typename... Q> | |
void | queryMapRow (const std::string &query, std::function< void(ResultSet &)> rowMapper, const T &value, const Q &... values) |
template<typename T, typename... Q> | |
void | queryExtract (const std::string &query, std::function< void(ResultSet &)> resExtractor, const T &value, const Q &... values) |
uint64_t | update (const std::string &query) |
template<typename T, typename... Q> | |
uint64_t | update (const std::string &query, const T &value, const Q &... values) |
template<typename T, typename Iterable> | |
uint64_t | batchUpdate (const std::string &query, std::function< void(PreparedStatement &, const T &)> mapper, const Iterable &values) |
bool | isValid () const noexcept |
Protected Member Functions | |
virtual ResultSet * | executeQuery (const std::string &query)=0 |
virtual uint64_t | executeUpdate (const std::string &query)=0 |
virtual void | sendStartTransaction ()=0 |
virtual void | sendCommit ()=0 |
virtual void | sendRollback ()=0 |
virtual PreparedStatement * | makePrepared (const std::string &query)=0 |
void | setValid (bool valid) noexcept |
Protected Attributes | |
bool | _valid |
bool | _transaction |
std::map< std::string, PreparedStatement * > | _stmts |
bool | _errors |
SQL connection virtual class.
Abstract layer for SQL connections management.
anch::sql::Connection::Connection | ( | ) |
Connection default constructor
SqlException | any error |
|
delete |
|
virtualnoexcept |
Connection destrcutor
uint64_t anch::sql::Connection::batchUpdate | ( | const std::string & | query, |
std::function< void(PreparedStatement &, const T &)> | mapper, | ||
const Iterable & | values ) |
Execute batch prepared statement
query | the SQL query |
mapper | the single value prepared statement mapper |
values | the values as structure or class |
SqlException | any error |
void anch::sql::Connection::begin | ( | ) |
Alias for startTransaction
SqlException | any error |
void anch::sql::Connection::commit | ( | ) |
Commit current SQL transaction.
If there is not transaction, this method does nothing.
SqlException | any error |
|
protectedpure virtual |
Execute SQL select query
query | the SQL query to execute |
SqlException | any error |
Implemented in anch::sql::MySQLConnection, anch::sql::PostgreSQLConnection, and anch::sql::SQLite3Connection.
|
protectedpure virtual |
Execute SQL update query
query | the SQL query to execute |
SqlException | any error |
Implemented in anch::sql::MySQLConnection, anch::sql::PostgreSQLConnection, and anch::sql::SQLite3Connection.
|
noexcept |
Valid status getter
|
protectedpure virtual |
Send SQL query to prepare SQL statement
query | the SQL query |
SqlException | any error |
Implemented in anch::sql::MySQLConnection, anch::sql::PostgreSQLConnection, and anch::sql::SQLite3Connection.
PreparedStatement & anch::sql::Connection::prepareStatement | ( | const std::string & | query | ) |
Prepare SQL statement if not already done.
query | the SQL query |
SqlException | any error |
ResultSet * anch::sql::Connection::query | ( | const std::string & | query | ) |
Execute SQL query
query | the SQL query to execute |
SqlException | any error |
ResultSet * anch::sql::Connection::query | ( | const std::string & | query, |
const T & | value, | ||
const Q &... | values ) |
Execute SQL prepared statement query
query | the SQL query to execute |
value | the first value to bind |
values | the other values |
SqlException | any error |
void anch::sql::Connection::queryExtract | ( | const std::string & | query, |
std::function< void(ResultSet &)> | resExtractor, | ||
const T & | value, | ||
const Q &... | values ) |
Execute query and extract result set
query | the SQL query to execute |
resExtractor | the result set extractor function |
value | the first value to bind |
values | the other values |
SqlException | any error |
void anch::sql::Connection::queryExtract | ( | const std::string & | sqlQuery, |
std::function< void(ResultSet &)> | resExtractor ) |
Execute query and extract result set
sqlQuery | the SQL query to execute |
resExtractor | the result set extractor function |
SqlException | any error |
void anch::sql::Connection::queryMapRow | ( | const std::string & | query, |
std::function< void(ResultSet &)> | rowMapper, | ||
const T & | value, | ||
const Q &... | values ) |
Execute query and treat each row of result set
query | the SQL query to execute |
rowMapper | the row mapper function |
value | the first value to bind |
values | the other values |
SqlException | any error |
void anch::sql::Connection::queryMapRow | ( | const std::string & | sqlQuery, |
std::function< void(ResultSet &)> | rowMapper ) |
Execute query and treat each row of result set
sqlQuery | the SQL query to execute |
rowMapper | the row mapper function |
SqlException | any error |
|
noexcept |
Release connection (used for connections' pool)
void anch::sql::Connection::rollback | ( | ) |
Rollback current SQL transaction.
If there is not transaction, this method does nothing.
SqlException | any error |
|
protectedpure virtual |
Send commit to database server
SqlException | any error |
Implemented in anch::sql::MySQLConnection, anch::sql::PostgreSQLConnection, and anch::sql::SQLite3Connection.
|
protectedpure virtual |
Send rollback to database server
SqlException | any error |
Implemented in anch::sql::MySQLConnection, anch::sql::PostgreSQLConnection, and anch::sql::SQLite3Connection.
|
protectedpure virtual |
Send start transaction to database server
SqlException | any error |
Implemented in anch::sql::MySQLConnection, anch::sql::PostgreSQLConnection, and anch::sql::SQLite3Connection.
|
protectednoexcept |
Valid status setter
valid | the status to set |
void anch::sql::Connection::startTransaction | ( | ) |
Start SQL transaction.
If there is a transaction on this database connection, this method does nothing.
SqlException | any error |
uint64_t anch::sql::Connection::update | ( | const std::string & | query | ) |
Execute update (INSERT, UPDATE or DELETE) SQL query.
query | the SQL query |
SqlException | any error |
uint64_t anch::sql::Connection::update | ( | const std::string & | query, |
const T & | value, | ||
const Q &... | values ) |
Execute update (INSERT, UPDATE or DELETE) SQL prepared statement.
query | the SQL query |
value | the first value to bind |
values | the other values |
SqlException | any error |
|
protected |
Error on current calls
|
protected |
Prepared statements
|
protected |
Is in SQL transaction
|
protected |
Is SQL connection valid