AnCH Framework  0.1
Another C++ Hack Framework
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
anch::sql::Connection Class Referenceabstract

SQL connection virtual class. More...

#include <connection.hpp>

Inheritance diagram for anch::sql::Connection:
Collaboration diagram for anch::sql::Connection:

Public Member Functions

 Connection () throw (SqlException)
 
 Connection (const Connection &)=delete
 
virtual ~Connection ()
 
void commit () throw (SqlException)
 
void rollback () throw (SqlException)
 
void setAutoCommit (bool autoCommit) throw (SqlException)
 
ResultSetquery (const std::string &query) throw (SqlException)
 
void queryMapRow (const std::string &sqlQuery, std::function< void(ResultSet &)> rowMapper) throw (SqlException)
 
void queryExtract (const std::string &sqlQuery, std::function< void(ResultSet &)> resExtractor) throw (SqlException)
 
uint64_t update (const std::string &query) throw (SqlException)
 
bool isAutoCommit () const
 
bool isValid () const
 

Protected Member Functions

virtual ResultSetexecuteQuery (const std::string &query)=0 throw (SqlException)
 
virtual uint64_t executeUpdate (const std::string &query)=0 throw (SqlException)
 
virtual void sendCommit ()=0 throw (SqlException)
 
virtual void sendRollback ()=0 throw (SqlException)
 
virtual void toggleAutoCommit (bool autoCommit)=0 throw (SqlException)
 
void setValid (bool valid)
 

Protected Attributes

bool _autoCommit
 
bool _valid
 

Detailed Description

SQL connection virtual class.

Abstract layer for SQL connections management.

Author
Vincent Lachenal
Since
0.1

Constructor & Destructor Documentation

Connection::Connection ( )
throw (SqlException
)

Connection default constructor

Exceptions
SqlExceptionany error
anch::sql::Connection::Connection ( const Connection )
delete

Prohibit Connection copy constructor

Connection::~Connection ( )
virtual

Connection destrcutor

Member Function Documentation

void Connection::commit ( )
throw (SqlException
)

Commit current SQL transaction.
If auto commit is set, this method does nothing.

Exceptions
SqlExceptionany error
virtual ResultSet* anch::sql::Connection::executeQuery ( const std::string &  query)
throw (SqlException
)
protectedpure virtual

Execute SQL select query

Parameters
querythe SQL query to execute
Returns
the result set which has to be deleted after use
Exceptions
SqlExceptionany error

Implemented in anch::sql::PostgreSQLConnection, anch::sql::MySQLConnection, and anch::sql::SQLite3Connection.

virtual uint64_t anch::sql::Connection::executeUpdate ( const std::string &  query)
throw (SqlException
)
protectedpure virtual

Execute SQL update query

Parameters
querythe SQL query to execute
Returns
the result set which has to be deleted after use
Exceptions
SqlExceptionany error

Implemented in anch::sql::PostgreSQLConnection, anch::sql::MySQLConnection, and anch::sql::SQLite3Connection.

bool anch::sql::Connection::isAutoCommit ( ) const
inline

Auto commit status getter

Returns
the status
bool anch::sql::Connection::isValid ( ) const
inline

Valid status getter

Returns
the status
ResultSet * Connection::query ( const std::string &  query)
throw (SqlException
)

Execute SQL query

Parameters
querythe SQL query to execute
Returns
the result set which has to be deleted after use
Exceptions
SqlExceptionany error
void Connection::queryExtract ( const std::string &  sqlQuery,
std::function< void(ResultSet &)>  resExtractor 
)
throw (SqlException
)

Execute query and extract result set

Parameters
sqlQuerythe SQL query to execute
resExtractorthe result set extractor function
Exceptions
SqlExceptionany error
void Connection::queryMapRow ( const std::string &  sqlQuery,
std::function< void(ResultSet &)>  rowMapper 
)
throw (SqlException
)

Execute query and treat each row of result set

Parameters
sqlQuerythe SQL query to execute
rowMapperthe row mapper function
Exceptions
SqlExceptionany error
void Connection::rollback ( )
throw (SqlException
)

Rollback current SQL transaction.
If auto commit is set, this method does nothing.

Exceptions
SqlExceptionany error
virtual void anch::sql::Connection::sendCommit ( )
throw (SqlException
)
protectedpure virtual

Send commit to database server

Exceptions
SqlExceptionany error

Implemented in anch::sql::PostgreSQLConnection, anch::sql::MySQLConnection, and anch::sql::SQLite3Connection.

virtual void anch::sql::Connection::sendRollback ( )
throw (SqlException
)
protectedpure virtual

Send rollback to database server

Exceptions
SqlExceptionany error

Implemented in anch::sql::PostgreSQLConnection, anch::sql::MySQLConnection, and anch::sql::SQLite3Connection.

void Connection::setAutoCommit ( bool  autoCommit)
throw (SqlException
)

Auto commit status setter.
Change auto commit status in database connection too.
This method does nothing if auto commit is same as before.

Parameters
autoCommitthe status
Exceptions
SqlExceptionany error
void anch::sql::Connection::setValid ( bool  valid)
inlineprotected

Valid status setter

Parameters
validthe status to set
virtual void anch::sql::Connection::toggleAutoCommit ( bool  autoCommit)
throw (SqlException
)
protectedpure virtual

Send auto commit status modification to server

Parameters
autoCommitthe status to send
Exceptions
SqlExceptionany error

Implemented in anch::sql::PostgreSQLConnection, anch::sql::MySQLConnection, and anch::sql::SQLite3Connection.

uint64_t Connection::update ( const std::string &  query)
throw (SqlException
)

Execute update (INSERT, UPDATE or DELETE) SQL query.

Parameters
querythe SQL query
Exceptions
SqlExceptionany error

Member Data Documentation

bool anch::sql::Connection::_autoCommit
protected

Auto commit

bool anch::sql::Connection::_valid
protected

Is SQL connection valid


The documentation for this class was generated from the following files: