#include <PoolDatabaseConnection.h>
Public Member Functions | |
void | open (const String &connectionString="") |
void | close () |
virtual bool | active () const |
virtual DBHandle | handle () const |
const DatabaseConnectionString & | connectionString () const |
void | connectionString (const DatabaseConnectionString &connectionString) |
virtual String | nativeConnectionString () const |
virtual DatabaseConnectionType | connectionType () const |
virtual String | driverDescription () const |
void | beginTransaction () |
void | commitTransaction () |
void | rollbackTransaction () |
bool | inTransaction () const |
virtual void | objectList (DatabaseObjectType objectType, Strings &objects)=0 |
void | bulkInsert (const String &tableName, const Strings &columnNames, const std::vector< VariantVector > &data) |
void | executeBatchFile (const String &batchFileName, Strings *errors=nullptr) |
void | executeBatchSQL (const sptk::Strings &batchSQL, Strings *errors=nullptr) |
Protected Member Functions | |
bool | getInTransaction () const |
void | setInTransaction (bool inTransaction) |
PoolDatabaseConnection (const String &connectionString, DatabaseConnectionType connectionType, std::chrono::seconds connectTimeout) | |
PoolDatabaseConnection (const PoolDatabaseConnection &)=delete | |
PoolDatabaseConnection (PoolDatabaseConnection &&) noexcept=default | |
PoolDatabaseConnection & | operator= (const PoolDatabaseConnection &)=delete |
PoolDatabaseConnection & | operator= (PoolDatabaseConnection &&) noexcept=default |
virtual void | _openDatabase (const String &connectionString) |
virtual void | closeDatabase () |
virtual void | driverBeginTransaction () |
virtual void | driverEndTransaction (bool commit) |
virtual void | _bulkInsert (const String &tableName, const Strings &columnNames, const std::vector< VariantVector > &data) |
virtual void | _executeBatchFile (const String &batchFileName, Strings *errors) |
virtual void | _executeBatchSQL (const sptk::Strings &batchSQL, Strings *errors) |
virtual void | connectionType (DatabaseConnectionType connType) |
void | bulkInsertRecords (const String &tableName, const Strings &columnNames, const std::vector< VariantVector >::const_iterator &begin, const std::vector< VariantVector >::const_iterator &end) |
std::chrono::seconds | connectTimout () const |
Protected Member Functions inherited from sptk::PoolDatabaseConnectionQueryMethods | |
void | querySetStmt (Query *q, SStmtHandle stmt) |
virtual String | queryError (const Query *query) const =0 |
virtual void | queryAllocStmt (Query *query)=0 |
virtual void | queryFreeStmt (Query *query)=0 |
virtual void | queryCloseStmt (Query *query)=0 |
virtual void | queryPrepare (Query *query)=0 |
virtual void | queryExecute (Query *query)=0 |
virtual int | queryColCount (Query *query)=0 |
virtual void | queryColAttributes (Query *query, int16_t column, int16_t descType, int32_t &value)=0 |
virtual void | queryColAttributes (Query *query, int16_t column, int16_t descType, char *buff, int len)=0 |
virtual void | queryBindParameters (Query *query)=0 |
virtual void | queryOpen (Query *query)=0 |
virtual void | queryFetch (Query *query)=0 |
virtual String | paramMark (unsigned paramIndex) |
void | notImplemented (const String &methodName) const |
bool | linkQuery (Query *q) |
bool | unlinkQuery (Query *q) |
void | disconnectAllQueries () |
Static Protected Member Functions | |
static void | logAndThrow (const String &method, const String &error) |
Static Protected Member Functions inherited from sptk::PoolDatabaseConnectionQueryMethods | |
static void | querySetPrepared (Query *q, bool pf) |
static void | querySetActive (Query *q, bool af) |
static void | querySetEof (Query *q, bool eof) |
Friends | |
class | Query |
class | QueryStatementManagement |
Database connector
Implements a thread-safe connection to generDOT_al database. It is used as a base class for actual database driver classes.
|
explicitprotected |
Constructor
Protected constructor prevents creating an instance of the DatabaseConnection. Instead, it is possible to create an instance of derived classes.
connectionString | The connection string |
|
protectedvirtual |
Executes bulk inserts of data from memory buffer
Data is inserted the fastest possible way. The server-specific format definition provides extra information about data. If format is empty than default server-specific data format is used. For instance, for PostgreSQL it is TAB-delimited data, with some escaped characters ('\t', '\n', '\r') and "\\N" for NULLs.
tableName | Table name to insert into |
columnNames | List of table columns to populate |
data | Data for bulk insert |
|
protectedvirtual |
Executes SQL batch file
Queries are executed in not prepared mode. Syntax of the SQL batch file is matching the native for the database.
batchFileName | SQL batch file |
errors | Errors during execution. If provided, then errors are stored here, instead of exceptions |
|
protectedvirtual |
Executes SQL batch queries
Queries are executed in not prepared mode. Syntax of the SQL batch file is matching the native for the database.
batchSQL | SQL batch file |
errors | Errors during execution. If provided, then errors are stored here, instead of exceptions |
|
protectedvirtual |
Opens the database connection.
This method should be overwritten in derived classes
connectionString | The ODBC connection string |
|
virtual |
Returns true if database is opened
void sptk::PoolDatabaseConnection::beginTransaction | ( | ) |
Begins the transaction
|
inline |
Executes bulk inserts of data from memory buffer
Data is inserted the fastest possible way. The server-specific format definition provides extra information about data. If format is empty than default server-specific data format is used. For instance, for PostgreSQL it is TAB-delimited data, with some escaped characters ('\t', '\n', '\r') and "\\N" for NULLs.
tableName | Table name to insert into |
columnNames | List of table columns to populate |
data | Data for bulk insert |
|
protected |
Create and execute single query to insert multiple records
tableName | Table name |
columnNames | Column names |
begin | Data rows begin iterator |
end | Data rows end iterator (not included into query) |
void sptk::PoolDatabaseConnection::close | ( | ) |
Closes the database connection. If unsuccessful throws an exception.
|
protectedvirtual |
Closes the database connection.
This method should be overwritten in derived classes
void sptk::PoolDatabaseConnection::commitTransaction | ( | ) |
Commits the transaction
|
inline |
Returns the connection string
void sptk::PoolDatabaseConnection::connectionString | ( | const DatabaseConnectionString & | connectionString | ) |
Set connecting string
connectionString | Connection string |
|
inlinevirtual |
Returns the connection type
|
inlineprotectedvirtual |
Set the connection type
|
inlineprotected |
Return connection timeout
|
protectedvirtual |
Begins the transaction
This method should be implemented in derived driver
|
inlinevirtual |
Returns the driver description
|
protectedvirtual |
Ends the transaction
This method should be implemented in derived driver
commit | Commit if true, rollback if false |
|
inline |
Executes SQL batch file
Queries are executed in not prepared mode. Syntax of the SQL batch file is matching the native for the database.
batchFileName | SQL batch file |
errors | Errors during execution. If provided, then errors are stored here, instead of exceptions |
|
inline |
Executes SQL batch queries
Queries are executed in not prepared mode. Syntax of the SQL batch file is matching the native for the database.
batchSQL | SQL batch file |
errors | Errors during execution. If provided, then errors are stored here, instead of exceptions |
|
virtual |
Returns the database connection handle
|
inline |
Reports true if in transaction
|
staticprotected |
Throws an exception
Before exception is thrown, it is logged into the logfile (if the logfile is defined)
method | Method name where error has occured |
error | Error text |
|
inlinevirtual |
Returns driver-specific connection string
|
pure virtual |
Lists database objects
Not implemented in DatabaseConnection. The derived database class must provide its own implementation
objectType | Object type to list |
objects | Object list (output) |
void sptk::PoolDatabaseConnection::open | ( | const String & | connectionString = "" | ) |
Opens the database connection
If unsuccessful throws an exception.
connectionString | The ODBC connection string |
void sptk::PoolDatabaseConnection::rollbackTransaction | ( | ) |
Rolls back the transaction