5 const std::chrono::minutes dbconnection::DEFAULT_TIMEOUT(10);
12 m_handle(other.m_handle)
16 m_handle(std::move(other.m_handle))
22 m_handle = other.m_handle;
30 assert(
this != &other);
31 m_handle = std::move(other.m_handle);
36 const std::string& filename,
38 const std::chrono::milliseconds timeout)
41 sqlite3_busy_timeout(
handle(), static_cast<int>(timeout.count()));
45 const std::string& filename,
46 const std::chrono::milliseconds timeout)
49 sqlite3_busy_timeout(
handle(), static_cast<int>(timeout.count()));
53 const std::u16string& filename,
54 const std::chrono::milliseconds timeout)
57 sqlite3_busy_timeout(
handle(), static_cast<int>(timeout.count()));
72 sqlite3_mutex* mutexPtr = sqlite3_db_mutex(m_handle.get());
73 if (mutexPtr ==
nullptr) {
74 throw SQLiteXXException(
"This database connection was not able to create a valid mutex.");
79 dbconnection::operator bool() const noexcept
81 return static_cast<bool>(m_handle);
86 return m_handle.get();
92 if (SQLITE_OK != sqlite3_open_v2(filename.c_str(), &connection,
static_cast<int>(mode),
nullptr)) {
94 sqlite3_close(connection);
98 m_handle.reset(connection, sqlite3_close);
104 if (SQLITE_OK != sqlite3_open16(filename.c_str(), &connection)) {
106 sqlite3_close(connection);
110 m_handle.reset(connection, sqlite3_close);
115 return sqlite3_last_insert_rowid(
handle());
dbconnection & operator=(const dbconnection &other) noexcept
Copy assignment operator.
sqlite3 * handle() const noexcept
Returns pointer to the underlying "sqlite3" object.
openmode
Different ways to open a dbconnection.
Encapsulation of the error code and message from SQLite3, based on std::runtime_error.
dbconnection() noexcept
Default constructor.
Helps with serializing access to a database connection.
long long row_id() const noexcept
Returns the rowid of the most recent successful "INSERT" into a rowid table or virtual table on datab...
static dbconnection wide_memory()
Create a purely in memory database with UTF-16 as the native byte order.
sqlite::mutex mutex()
Returns a mutex that serializes access to the database.
static dbconnection memory()
Create a purely in memory database.
Class that represents a connection to a database.
void open(const std::string &filename, openmode mode=openmode::read_write|openmode::create)
Open an SQLite database file as specified by the filename argument.