A thread-safe sqlite (sqlcipher) database.
More...
#include <sqlitedatabase.h>
A thread-safe sqlite (sqlcipher) database.
◆ SqliteDatabase() [1/3]
Nickvision::Database::SqliteDatabase::SqliteDatabase |
( |
const std::filesystem::path & | path, |
|
|
int | flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE ) |
Constructs a SqliteDatabase.
If the database if not encrypted, it will be unlocked automatically.
- Parameters
-
path | The path to the database file |
flags | The flags for opening the database |
- Exceptions
-
std::runtime_error | Thrown if error in executing sql statement |
◆ SqliteDatabase() [2/3]
Nickvision::Database::SqliteDatabase::SqliteDatabase |
( |
const SqliteDatabase & | | ) |
|
|
delete |
◆ SqliteDatabase() [3/3]
Nickvision::Database::SqliteDatabase::SqliteDatabase |
( |
SqliteDatabase && | other | ) |
|
|
noexcept |
◆ ~SqliteDatabase()
Nickvision::Database::SqliteDatabase::~SqliteDatabase |
( |
| ) |
|
|
noexcept |
◆ createStatement()
SqliteStatement Nickvision::Database::SqliteDatabase::createStatement |
( |
const std::string & | command | ) |
|
Creates a new SqlStatement for the database.
Executing the statement is controlled by calling step() on the statement object.
- Parameters
-
command | The command to bind to the statement. |
- Returns
- The new SqlStatement if successful
-
An empty SqlStatement if failed (can be checked with operator bool())
- Exceptions
-
std::runtime_error | Thrown if error in executing sql statement |
◆ execute()
bool Nickvision::Database::SqliteDatabase::execute |
( |
const std::string & | command | ) |
|
|
noexcept |
Executes a sql command on the database.
- Parameters
-
command | The command to execute |
- Returns
- True if command returned SQLITE_OK, else false
◆ getPath()
const std::filesystem::path & Nickvision::Database::SqliteDatabase::getPath |
( |
| ) |
const |
|
noexcept |
Gets the path of the database file.
- Returns
- The database file path
◆ isEncrypted()
bool Nickvision::Database::SqliteDatabase::isEncrypted |
( |
| ) |
const |
|
noexcept |
Gets whether or not the database is encrypted.
- Returns
- True if encrypted, else false
◆ isUnlocked()
bool Nickvision::Database::SqliteDatabase::isUnlocked |
( |
| ) |
const |
|
noexcept |
Gets whether or not the database is unlocked.
- Returns
- True if unlocked, else false
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ registerFunction()
bool Nickvision::Database::SqliteDatabase::registerFunction |
( |
const std::string & | name, |
|
|
const SqliteCustomFunction & | func, |
|
|
int | expectedArgs = -1 ) |
|
noexcept |
Registers a custom sql function to the database.
- Parameters
-
name | The name of the sql function |
func | The custom sql function |
expectedArgs | The number of args the sql function expects to receive (specify -1 for unlimited number of args) |
- Returns
- True if function registered, else false
◆ setPassword()
bool Nickvision::Database::SqliteDatabase::setPassword |
( |
const std::string & | password | ) |
|
Sets the database's password.
If the database is not encrypted, it will be encrypted with the password.
If the database is encrypted and locked, this method will return false.
If the database is encrypted and unlocked and the password is empty, it will be decrypted.
If the database is encrypted and unlocked and the password is not empty, it will be reencrypted with the new password.
- Parameters
-
password | The new database password |
- Returns
- True if successful, else false
- Exceptions
-
std::runtime_error | Thrown if database cannot be opened |
◆ unlock()
bool Nickvision::Database::SqliteDatabase::unlock |
( |
const std::string & | password | ) |
|
|
noexcept |
Unlocks the database.
If the database is not encrypted, this method will have no effect and return true.
If the database is encrypted, this method must be called before any other operations.
- Parameters
-
password | The password of the database |
- Returns
- True if unlocked, else false
The documentation for this class was generated from the following file: