sptk2 logo
SPTK Home Page
Public Member Functions | List of all members
sptk::AutoDatabaseConnection Class Reference

#include <AutoDatabaseConnection.h>

Public Member Functions

 AutoDatabaseConnection (DatabaseConnectionPool &connectionPool)
 
 AutoDatabaseConnection (const AutoDatabaseConnection &)=delete
 
 AutoDatabaseConnection (AutoDatabaseConnection &&)=default
 
 ~AutoDatabaseConnection ()
 
AutoDatabaseConnectionoperator= (const AutoDatabaseConnection &)=delete
 
AutoDatabaseConnectionoperator= (AutoDatabaseConnection &&)=delete
 
PoolDatabaseConnectionconnection ()
 
void open (const String &connectionString="") const
 
void close () const
 
bool active () const
 
const DatabaseConnectionStringconnectionString () const
 
DatabaseConnectionType connectionType () const
 
String driverDescription () const
 
void beginTransaction () const
 
void commitTransaction () const
 
void rollbackTransaction () const
 
int inTransaction () const
 
void objectList (DatabaseObjectType objectType, Strings &objects) const
 
void bulkInsert (const String &tableName, const Strings &columnNames, const std::vector< VariantVector > &data) const
 
void executeBatchFile (const String &batchFileName, Strings *errors=nullptr) const
 
void executeBatchSQL (const sptk::Strings &batchSQL, Strings *errors=nullptr) const
 

Detailed Description

Wrapper for CDatabase connection that automatically handles connection create and release

Constructor & Destructor Documentation

◆ AutoDatabaseConnection()

sptk::AutoDatabaseConnection::AutoDatabaseConnection ( DatabaseConnectionPool connectionPool)
explicit

Constructor Automatically gets connection from connection pool

Parameters
connectionPoolDatabase connection pool

◆ ~AutoDatabaseConnection()

sptk::AutoDatabaseConnection::~AutoDatabaseConnection ( )

Destructor Releases connection to connection pool

Member Function Documentation

◆ active()

bool sptk::AutoDatabaseConnection::active ( ) const
inline

Returns true if database is opened

◆ beginTransaction()

void sptk::AutoDatabaseConnection::beginTransaction ( ) const
inline

Begins the transaction

◆ bulkInsert()

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

◆ close()

void sptk::AutoDatabaseConnection::close ( ) const
inline

Closes the database connection. If unsuccessful throws an exception.

◆ commitTransaction()

void sptk::AutoDatabaseConnection::commitTransaction ( ) const
inline

Commits the transaction

◆ connection()

PoolDatabaseConnection * sptk::AutoDatabaseConnection::connection ( )

Returns database connection acquired from the connection pool

◆ connectionString()

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

Returns the connection string

Referenced by open().

◆ connectionType()

DatabaseConnectionType sptk::AutoDatabaseConnection::connectionType ( ) const
inline

Returns the connection type

◆ driverDescription()

String sptk::AutoDatabaseConnection::driverDescription ( ) const
inline

Returns the driver description

◆ executeBatchFile()

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

◆ inTransaction()

int sptk::AutoDatabaseConnection::inTransaction ( ) const
inline

Reports true if in transaction

◆ objectList()

void sptk::AutoDatabaseConnection::objectList ( DatabaseObjectType  objectType,
Strings objects 
) const
inline

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::AutoDatabaseConnection::open ( const String connectionString = "") const
inline

Opens the database connection

If unsuccessful throws an exception.

Parameters
connectionStringThe ODBC connection string

References connectionString().

◆ rollbackTransaction()

void sptk::AutoDatabaseConnection::rollbackTransaction ( ) const
inline

Rolls back the transaction


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

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