Zserio C++ runtime library  1.0.2
Built for Zserio 2.14.1
zserio::SqliteConnection Class Reference

#include <SqliteConnection.h>

Public Types

enum  ConnectionType { INTERNAL_CONNECTION , EXTERNAL_CONNECTION }
 

Public Member Functions

 SqliteConnection (sqlite3 *connection=nullptr, ConnectionType connectionType=INTERNAL_CONNECTION)
 
 ~SqliteConnection ()
 
void reset (sqlite3 *connection=nullptr, ConnectionType connectionType=INTERNAL_CONNECTION)
 
ConnectionType getConnectionType () const
 
sqlite3 * getConnection ()
 
void executeUpdate (StringView sqlQuery)
 
sqlite3_stmt * prepareStatement (StringView sqlQuery)
 
bool startTransaction ()
 
void endTransaction (bool wasTransactionStarted)
 
 SqliteConnection (const SqliteConnection &)=delete
 
SqliteConnectionoperator= (const SqliteConnection &)=delete
 
 SqliteConnection (SqliteConnection &&)=delete
 
SqliteConnectionoperator= (SqliteConnection &&)=delete
 

Detailed Description

Helper class to keep sqlite3 connection and ensure its safe destruction.

The class also provides simple interface to execute SQLite queries.

Definition at line 20 of file SqliteConnection.h.

Member Enumeration Documentation

◆ ConnectionType

Connection type.

Enumerator
INTERNAL_CONNECTION 

Internal connection which must be released in destructor.

EXTERNAL_CONNECTION 

External connection managed from outside.

Definition at line 26 of file SqliteConnection.h.

Constructor & Destructor Documentation

◆ SqliteConnection() [1/3]

zserio::SqliteConnection::SqliteConnection ( sqlite3 *  connection = nullptr,
ConnectionType  connectionType = INTERNAL_CONNECTION 
)
inlineexplicit

Constructor.

Parameters
connectionPointer to the SQLite connection.
connectionTypeType of the connection. Default is INTERNAL_CONNECTION.

Definition at line 129 of file SqliteConnection.h.

◆ ~SqliteConnection()

zserio::SqliteConnection::~SqliteConnection ( )
inline

Destructor.

Definition at line 134 of file SqliteConnection.h.

◆ SqliteConnection() [2/3]

zserio::SqliteConnection::SqliteConnection ( const SqliteConnection )
delete

Copying and moving is disallowed!

◆ SqliteConnection() [3/3]

zserio::SqliteConnection::SqliteConnection ( SqliteConnection &&  )
delete

Copying and moving is disallowed!

Member Function Documentation

◆ endTransaction()

void zserio::SqliteConnection::endTransaction ( bool  wasTransactionStarted)
inline

Terminates the current transaction.

The parameter wasTransactionStarted is used for convenience since it's then easier to write code which uses transactions.

bool wasTransactionStarted = connection.startTransaction(); // transaction may be already started
// execute queries
// ...
// terminates the transaction only if it was started by the corresponding startTransaction call.
connection.endTransaction(wasTransactionStarted);
Parameters
wasTransactionStartedWhen false, the call does actually nothing.

Definition at line 198 of file SqliteConnection.h.

◆ executeUpdate()

void zserio::SqliteConnection::executeUpdate ( StringView  sqlQuery)
inline

Executes a single query which doesn't need to return anything - e.g. DML.

Parameters
sqlQueryThe query string.

Definition at line 161 of file SqliteConnection.h.

◆ getConnection()

sqlite3 * zserio::SqliteConnection::getConnection ( )
inline

Gets the current connection.

Returns
SQLite connection.

Definition at line 156 of file SqliteConnection.h.

◆ getConnectionType()

SqliteConnection::ConnectionType zserio::SqliteConnection::getConnectionType ( ) const
inline

Gets the current connection type.

When connection is NULL, the connection type is insignificant.

Returns
Connection type.

Definition at line 151 of file SqliteConnection.h.

◆ operator=() [1/2]

SqliteConnection& zserio::SqliteConnection::operator= ( const SqliteConnection )
delete

Copying and moving is disallowed!

◆ operator=() [2/2]

SqliteConnection& zserio::SqliteConnection::operator= ( SqliteConnection &&  )
delete

Copying and moving is disallowed!

◆ prepareStatement()

sqlite3_stmt * zserio::SqliteConnection::prepareStatement ( StringView  sqlQuery)
inline

Prepares the SQLite statement for the given query.

Note that the user is responsible to proper statement finalization using sqlite3_finalize!

Parameters
sqlQueryThe query string.
Returns
Prepared SQLite statement.

Definition at line 172 of file SqliteConnection.h.

◆ reset()

void zserio::SqliteConnection::reset ( sqlite3 *  connection = nullptr,
ConnectionType  connectionType = INTERNAL_CONNECTION 
)
inline

Resets the connection.

Parameters
connectionNew connection to set. Default is NULL - i.e. unset.
connectionTypeType of the new connection.

Definition at line 139 of file SqliteConnection.h.

◆ startTransaction()

bool zserio::SqliteConnection::startTransaction ( )
inline

Starts a new transaction if a transaction is not already started.

Returns
True when the new transaction was started. False when a transaction is already started.

Definition at line 186 of file SqliteConnection.h.


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