9#include <ocpp/common/support_older_cpp_versions.hpp>
11#include "sqlite_statement.hpp"
13namespace ocpp::common {
41 [[nodiscard]]
virtual std::unique_ptr<DatabaseTransactionInterface>
begin_transaction() = 0;
48 virtual std::unique_ptr<SQLiteStatementInterface>
new_statement(
const std::string& sql) = 0;
69 const fs::path database_file_path;
70 std::atomic_uint32_t open_count;
71 std::timed_mutex transaction_mutex;
73 bool close_connection_internal(
bool force_close);
83 [[nodiscard]] std::unique_ptr<DatabaseTransactionInterface>
begin_transaction()
override;
86 std::unique_ptr<SQLiteStatementInterface>
new_statement(
const std::string& sql)
override;
90 bool clear_table(
const std::string& table)
override;
Definition: database_connection.hpp:29
virtual uint32_t get_user_version()=0
Helper function to get the user version of the database.
virtual std::unique_ptr< DatabaseTransactionInterface > begin_transaction()=0
Start a transaction on the database. Returns an object holding the transaction.
virtual int64_t get_last_inserted_rowid()=0
Gets the last inserted rowid.
virtual const char * get_error_message()=0
Returns the latest error message from sqlite3.
virtual bool open_connection()=0
Opens the database connection. Returns true if succeeded.
virtual std::unique_ptr< SQLiteStatementInterface > new_statement(const std::string &sql)=0
Returns a new SQLiteStatementInterface to be used to perform more advanced sql statements.
virtual bool close_connection()=0
Closes the database connection. Returns true if succeeded.
virtual void set_user_version(uint32_t version)=0
Helper function to set the user version of the database to version.
virtual bool execute_statement(const std::string &statement)=0
Immediately executes statement. Returns true if succeeded.
virtual bool clear_table(const std::string &table)=0
Clears the table with name table. Returns true if succeeded.
Definition: database_connection.hpp:66
std::unique_ptr< SQLiteStatementInterface > new_statement(const std::string &sql) override
Returns a new SQLiteStatementInterface to be used to perform more advanced sql statements.
Definition: database_connection.cpp:129
int64_t get_last_inserted_rowid() override
Gets the last inserted rowid.
Definition: database_connection.cpp:137
bool close_connection() override
Closes the database connection. Returns true if succeeded.
Definition: database_connection.cpp:81
bool execute_statement(const std::string &statement) override
Immediately executes statement. Returns true if succeeded.
Definition: database_connection.cpp:111
std::unique_ptr< DatabaseTransactionInterface > begin_transaction() override
Start a transaction on the database. Returns an object holding the transaction.
Definition: database_connection.cpp:125
uint32_t get_user_version() override
Helper function to get the user version of the database.
Definition: database_connection.cpp:141
bool open_connection() override
Opens the database connection. Returns true if succeeded.
Definition: database_connection.cpp:59
const char * get_error_message() override
Returns the latest error message from sqlite3.
Definition: database_connection.cpp:121
void set_user_version(uint32_t version) override
Helper function to set the user version of the database to version.
Definition: database_connection.cpp:150
bool clear_table(const std::string &table) override
Clears the table with name table. Returns true if succeeded.
Definition: database_connection.cpp:133
Helper class for transactions. Will lock the database interface from new transaction until commit() o...
Definition: database_connection.hpp:17
virtual ~DatabaseTransactionInterface()=default
Destructor of transaction: Will by default rollback unless commit() is called.
virtual void commit()=0
Commits the transaction and release the lock on the database interface.
virtual void rollback()=0
Aborts the transaction and release the lock on the database interface.