Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::db::DriverInstance Class Referenceabstract

Database-driven instance class. More...

#include <DriverInstance.h>

Inheritance diagram for sese::db::DriverInstance:
sese::db::impl::MariaDriverInstanceImpl sese::db::impl::PostgresDriverInstanceImpl sese::db::impl::SqliteDriverInstanceImpl

Public Types

using Ptr = std::unique_ptr<DriverInstance>
 

Public Member Functions

virtual ~DriverInstance () noexcept=default
 Destructors.
 
virtual ResultSet::Ptr executeQuery (const char *sql) noexcept=0
 
virtual int64_t executeUpdate (const char *sql) noexcept=0
 
virtual PreparedStatement::Ptr createStatement (const char *sql) noexcept=0
 
virtual int getLastError () const noexcept=0
 
virtual const char * getLastErrorMessage () const noexcept=0
 
virtual bool setAutoCommit (bool enable) noexcept=0
 
virtual bool getAutoCommit (bool &status) noexcept=0
 
virtual bool rollback () noexcept=0
 
virtual bool commit () noexcept=0
 
virtual bool getInsertId (int64_t &id) const noexcept=0
 
virtual bool begin () noexcept=0
 
ErrorCode getErrorCode () const
 

Detailed Description

Database-driven instance class.

Member Typedef Documentation

◆ Ptr

Constructor & Destructor Documentation

◆ ~DriverInstance()

virtual sese::db::DriverInstance::~DriverInstance ( )
virtualdefaultnoexcept

Destructors.

Member Function Documentation

◆ begin()

virtual bool sese::db::DriverInstance::begin ( )
nodiscardpure virtualnoexcept

Starts the transaction

Return values
falseIf the transaction start fails

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

◆ commit()

virtual bool sese::db::DriverInstance::commit ( )
nodiscardpure virtualnoexcept

Commits the transaction

Return values
falseIf the commit fails

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

◆ createStatement()

virtual PreparedStatement::Ptr sese::db::DriverInstance::createStatement ( const char * sql)
pure virtualnoexcept

Creates a prepared statement object

Parameters
sqlThe SQL query string
Returns
The prepared statement object
Return values
nullptrIf creation fails

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

◆ executeQuery()

virtual ResultSet::Ptr sese::db::DriverInstance::executeQuery ( const char * sql)
pure virtualnoexcept

Execute the query

Parameters
sqlQuery statements
Returns
The result set that was queried
Return values
nullptrQuery failed

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

◆ executeUpdate()

virtual int64_t sese::db::DriverInstance::executeUpdate ( const char * sql)
pure virtualnoexcept

Execute the update

Parameters
sqlUpdate statements
Returns
Count the number of rows updated
Return values
-1Execution failed

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

◆ getAutoCommit()

virtual bool sese::db::DriverInstance::getAutoCommit ( bool & status)
nodiscardpure virtualnoexcept

Checks whether auto-commit is enabled

Warning
Since libpq does not support retrieving the autoCommit status, it is recommended to use the command line to obtain this value when using PostgreSQL.
Return values
falseIf the operation fails

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

◆ getErrorCode()

ErrorCode sese::db::DriverInstance::getErrorCode ( ) const
inline

◆ getInsertId()

virtual bool sese::db::DriverInstance::getInsertId ( int64_t & id) const
nodiscardpure virtualnoexcept

Retrieves the auto-incremented ID

Warning
Since libpq does not support retrieving the auto-incremented ID, it is recommended to use the command line with the query ‘SELECT currval(pg_get_serial_sequence('tabName’, 'colName'))` to get the auto-incremented ID when using PostgreSQL.
Return values
falseIf the retrieval fails

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

◆ getLastError()

virtual int sese::db::DriverInstance::getLastError ( ) const
nodiscardpure virtualnoexcept

Retrieves the error code corresponding to the instance's driver

Returns
The error code

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

Referenced by getErrorCode().

◆ getLastErrorMessage()

virtual const char * sese::db::DriverInstance::getLastErrorMessage ( ) const
nodiscardpure virtualnoexcept

Retrieves the error message corresponding to the instance's driver (null check required)

Returns
The error message

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

Referenced by getErrorCode().

◆ rollback()

virtual bool sese::db::DriverInstance::rollback ( )
nodiscardpure virtualnoexcept

Rolls back the transaction

Return values
falseIf the rollback fails

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.

◆ setAutoCommit()

virtual bool sese::db::DriverInstance::setAutoCommit ( bool enable)
nodiscardpure virtualnoexcept

Sets the transaction auto-commit mode

Warning
Since libpq does not support setting autocommit, and the autoCommit property is global, it is recommended to use begin() to start a transaction when using PostgreSQL.
Since sqlite3 does not support setting autocommit, it is recommended to use begin() to start a transaction when using SQLite.
Parameters
enableEnable or disable auto-commit mode
Return values
falseIf the operation fails

Implemented in sese::db::impl::MariaDriverInstanceImpl, sese::db::impl::PostgresDriverInstanceImpl, and sese::db::impl::SqliteDriverInstanceImpl.


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