sptk2 logo
SPTK Home Page
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
sptk::PoolDatabaseConnection Class Referenceabstract

#include <PoolDatabaseConnection.h>

Inheritance diagram for sptk::PoolDatabaseConnection:
sptk::PoolDatabaseConnectionQueryMethods

Public Member Functions

void open (const String &connectionString="")
 
void close ()
 
virtual bool active () const
 
virtual DBHandle handle () const
 
const DatabaseConnectionStringconnectionString () 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
 
PoolDatabaseConnectionoperator= (const PoolDatabaseConnection &)=delete
 
PoolDatabaseConnectionoperator= (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
 

Detailed Description

Database connector

Implements a thread-safe connection to generDOT_al database. It is used as a base class for actual database driver classes.

Constructor & Destructor Documentation

◆ PoolDatabaseConnection()

sptk::PoolDatabaseConnection::PoolDatabaseConnection ( const String connectionString,
DatabaseConnectionType  connectionType,
std::chrono::seconds  connectTimeout 
)
explicitprotected

Constructor

Protected constructor prevents creating an instance of the DatabaseConnection. Instead, it is possible to create an instance of derived classes.

Parameters
connectionStringThe connection string

Member Function Documentation

◆ _bulkInsert()

virtual void sptk::PoolDatabaseConnection::_bulkInsert ( const String tableName,
const Strings columnNames,
const std::vector< VariantVector > &  data 
)
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.

Parameters
tableNameTable name to insert into
columnNamesList of table columns to populate
dataData for bulk insert

◆ _executeBatchFile()

virtual void sptk::PoolDatabaseConnection::_executeBatchFile ( const String batchFileName,
Strings errors 
)
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.

Parameters
batchFileNameSQL batch file
errorsErrors during execution. If provided, then errors are stored here, instead of exceptions

◆ _executeBatchSQL()

virtual void sptk::PoolDatabaseConnection::_executeBatchSQL ( const sptk::Strings batchSQL,
Strings errors 
)
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.

Parameters
batchSQLSQL batch file
errorsErrors during execution. If provided, then errors are stored here, instead of exceptions

◆ _openDatabase()

virtual void sptk::PoolDatabaseConnection::_openDatabase ( const String connectionString)
protectedvirtual

Opens the database connection.

This method should be overwritten in derived classes

Parameters
connectionStringThe ODBC connection string

◆ active()

virtual bool sptk::PoolDatabaseConnection::active ( ) const
virtual

Returns true if database is opened

◆ beginTransaction()

void sptk::PoolDatabaseConnection::beginTransaction ( )

Begins the transaction

◆ bulkInsert()

void sptk::PoolDatabaseConnection::bulkInsert ( const String tableName,
const Strings columnNames,
const std::vector< VariantVector > &  data 
)
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.

Parameters
tableNameTable name to insert into
columnNamesList of table columns to populate
dataData for bulk insert

◆ bulkInsertRecords()

void sptk::PoolDatabaseConnection::bulkInsertRecords ( const String tableName,
const Strings columnNames,
const std::vector< VariantVector >::const_iterator &  begin,
const std::vector< VariantVector >::const_iterator &  end 
)
protected

Create and execute single query to insert multiple records

Parameters
tableNameTable name
columnNamesColumn names
beginData rows begin iterator
endData rows end iterator (not included into query)

◆ close()

void sptk::PoolDatabaseConnection::close ( )

Closes the database connection. If unsuccessful throws an exception.

◆ closeDatabase()

virtual void sptk::PoolDatabaseConnection::closeDatabase ( )
protectedvirtual

Closes the database connection.

This method should be overwritten in derived classes

◆ commitTransaction()

void sptk::PoolDatabaseConnection::commitTransaction ( )

Commits the transaction

◆ connectionString() [1/2]

const DatabaseConnectionString & sptk::PoolDatabaseConnection::connectionString ( ) const
inline

Returns the connection string

◆ connectionString() [2/2]

void sptk::PoolDatabaseConnection::connectionString ( const DatabaseConnectionString connectionString)

Set connecting string

Parameters
connectionStringConnection string

◆ connectionType() [1/2]

virtual DatabaseConnectionType sptk::PoolDatabaseConnection::connectionType ( ) const
inlinevirtual

Returns the connection type

◆ connectionType() [2/2]

virtual void sptk::PoolDatabaseConnection::connectionType ( DatabaseConnectionType  connType)
inlineprotectedvirtual

Set the connection type

◆ connectTimout()

std::chrono::seconds sptk::PoolDatabaseConnection::connectTimout ( ) const
inlineprotected

Return connection timeout

Returns
connection timeout

◆ driverBeginTransaction()

virtual void sptk::PoolDatabaseConnection::driverBeginTransaction ( )
protectedvirtual

Begins the transaction

This method should be implemented in derived driver

◆ driverDescription()

virtual String sptk::PoolDatabaseConnection::driverDescription ( ) const
inlinevirtual

Returns the driver description

◆ driverEndTransaction()

virtual void sptk::PoolDatabaseConnection::driverEndTransaction ( bool  commit)
protectedvirtual

Ends the transaction

This method should be implemented in derived driver

Parameters
commitCommit if true, rollback if false

◆ executeBatchFile()

void sptk::PoolDatabaseConnection::executeBatchFile ( const String batchFileName,
Strings errors = nullptr 
)
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.

Parameters
batchFileNameSQL batch file
errorsErrors during execution. If provided, then errors are stored here, instead of exceptions

◆ executeBatchSQL()

void sptk::PoolDatabaseConnection::executeBatchSQL ( const sptk::Strings batchSQL,
Strings errors = nullptr 
)
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.

Parameters
batchSQLSQL batch file
errorsErrors during execution. If provided, then errors are stored here, instead of exceptions

◆ handle()

virtual DBHandle sptk::PoolDatabaseConnection::handle ( ) const
virtual

Returns the database connection handle

◆ inTransaction()

bool sptk::PoolDatabaseConnection::inTransaction ( ) const
inline

Reports true if in transaction

◆ logAndThrow()

static void sptk::PoolDatabaseConnection::logAndThrow ( const String method,
const String error 
)
staticprotected

Throws an exception

Before exception is thrown, it is logged into the logfile (if the logfile is defined)

Parameters
methodMethod name where error has occured
errorError text

◆ nativeConnectionString()

virtual String sptk::PoolDatabaseConnection::nativeConnectionString ( ) const
inlinevirtual

Returns driver-specific connection string

◆ objectList()

virtual void sptk::PoolDatabaseConnection::objectList ( DatabaseObjectType  objectType,
Strings objects 
)
pure virtual

Lists database objects

Not implemented in DatabaseConnection. The derived database class must provide its own implementation

Parameters
objectTypeObject type to list
objectsObject list (output)

◆ open()

void sptk::PoolDatabaseConnection::open ( const String connectionString = "")

Opens the database connection

If unsuccessful throws an exception.

Parameters
connectionStringThe ODBC connection string

◆ rollbackTransaction()

void sptk::PoolDatabaseConnection::rollbackTransaction ( )

Rolls back the transaction


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

Fri Oct 14 2022 09:58:44: SPTK 5.4.1