libnick 2024.12.0
A cross-platform base for native Nickvision applications.
|
A sqlite (sqlcipher) database. More...
#include <sqldatabase.h>
Public Member Functions | |
SqlDatabase (const std::filesystem::path &path, int flags) | |
Constructs a SqlDatabase. | |
SqlDatabase (const SqlDatabase &database) | |
Copies a SqlDatabase object. | |
SqlDatabase (SqlDatabase &&database) noexcept | |
Moves a SqlDatabase object. | |
const std::filesystem::path & | getPath () const |
Gets the path of the database file. | |
bool | isEncrypted () const |
Gets whether or not the database is encrypted. | |
sqlite3 * | c_obj () |
Returns the underlying sqlite3 object pointer for the database. | |
bool | unlock (const std::string &password) |
Unlocks the database. | |
bool | changePassword (const std::string &password) |
Changes the database's password. | |
bool | exec (const std::string &command) |
Executes an sql command on the database. | |
SqlStatement | createStatement (const std::string &command) |
Creates an new SqlStatement for the database. | |
bool | registerFunction (const std::string &name, const SqliteCustomFunction &func, int expectedArgs=-1) |
Registers a custom sql function to the database. | |
SqlDatabase & | operator= (const SqlDatabase &database) |
Copies a SqlDatabase object. | |
SqlDatabase & | operator= (SqlDatabase &&database) noexcept |
Moves a SqlDatabase object. | |
operator bool () const | |
Gets whether or not the object is valid or not. | |
A sqlite (sqlcipher) database.
Nickvision::Database::SqlDatabase::SqlDatabase | ( | const std::filesystem::path & | path, |
int | flags ) |
Constructs a SqlDatabase.
path | The path to the database file |
flags | The flags for opening the database |
std::runtime_error | Thrown if error in executing sql statement |
Nickvision::Database::SqlDatabase::SqlDatabase | ( | const SqlDatabase & | database | ) |
Copies a SqlDatabase object.
database | The object to move |
|
noexcept |
Moves a SqlDatabase object.
database | The object to move |
sqlite3 * Nickvision::Database::SqlDatabase::c_obj | ( | ) |
Returns the underlying sqlite3 object pointer for the database.
Using this method is strongly discouraged, as you can break the state of this object.
bool Nickvision::Database::SqlDatabase::changePassword | ( | const std::string & | password | ) |
Changes the database's password.
Passing an empty string will unencrypt the database.
Changing the password on an encrypted database requires that the database be unlocked first, even if removing the password.
password | The new database password |
std::runtime_error | Thrown if error in executing sql statement |
SqlStatement Nickvision::Database::SqlDatabase::createStatement | ( | const std::string & | command | ) |
Creates an new SqlStatement for the database.
command | The command to bind to the statement. |
std::runtime_error | Thrown if error in executing sql statement |
bool Nickvision::Database::SqlDatabase::exec | ( | const std::string & | command | ) |
Executes an sql command on the database.
command | The command to execute |
const std::filesystem::path & Nickvision::Database::SqlDatabase::getPath | ( | ) | const |
Gets the path of the database file.
bool Nickvision::Database::SqlDatabase::isEncrypted | ( | ) | const |
Gets whether or not the database is encrypted.
Nickvision::Database::SqlDatabase::operator bool | ( | ) | const |
Gets whether or not the object is valid or not.
SqlDatabase & Nickvision::Database::SqlDatabase::operator= | ( | const SqlDatabase & | database | ) |
|
noexcept |
bool Nickvision::Database::SqlDatabase::registerFunction | ( | const std::string & | name, |
const SqliteCustomFunction & | func, | ||
int | expectedArgs = -1 ) |
Registers a custom sql function to the database.
name | The name of the sql function |
expectedArgs | The number of args the sql function expects to receive (specify -1 for unlimited number of args) |
func | The sql function |
bool Nickvision::Database::SqlDatabase::unlock | ( | const std::string & | password | ) |
Unlocks the database.
If the database is not encrypted and is newly created, this will encrypt and set its password.
password | The password of the database |