libdballe 9.6
|
Database connection. More...
#include <sqlite.h>
Public Member Functions | |
SQLiteConnection (const SQLiteConnection &)=delete | |
SQLiteConnection (const SQLiteConnection &&)=delete | |
SQLiteConnection & | operator= (const SQLiteConnection &)=delete |
operator sqlite3 * () | |
void | open_file (const std::string &pathname, int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE) |
void | open_memory (int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE) |
void | open_private_file (int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE) |
std::unique_ptr< Transaction > | transaction (bool readonly=false) override |
Begin a transaction. | |
std::unique_ptr< SQLiteStatement > | sqlitestatement (const std::string &query) |
bool | has_table (const std::string &name) override |
Check if the database contains a table. | |
std::string | get_setting (const std::string &key) override |
Get a value from the settings table. | |
void | set_setting (const std::string &key, const std::string &value) override |
Set a value in the settings table. | |
void | drop_settings () override |
Drop the settings table. | |
void | execute (const std::string &query) override |
Execute a query without reading its results. | |
void | explain (const std::string &query, FILE *out) override |
Format and print the EXPLAIN output for the query to the given file. | |
void | drop_table_if_exists (const char *name) |
Delete a table in the database if it exists, otherwise do nothing. | |
int | get_last_insert_id () |
Return LAST_INSERT_ID or LAST_INSER_ROWID or whatever is appropriate for the current database, if supported. | |
int | changes () |
Count the number of rows modified by the last query that was run. | |
void | exec (const std::string &query) |
Wrap sqlite3_exec, without a callback. | |
void | exec_nothrow (const std::string &query) noexcept |
![]() | |
const std::string & | get_url () const |
virtual std::unique_ptr< Transaction > | transaction (bool readonly=false)=0 |
Begin a transaction. | |
virtual bool | has_table (const std::string &name)=0 |
Check if the database contains a table. | |
virtual std::string | get_setting (const std::string &key)=0 |
Get a value from the settings table. | |
virtual void | set_setting (const std::string &key, const std::string &value)=0 |
Set a value in the settings table. | |
virtual void | drop_settings ()=0 |
Drop the settings table. | |
virtual void | add_datetime (Querybuf &qb, const Datetime &dt) const |
Format a datetime and add it to the querybuf. | |
virtual void | execute (const std::string &query)=0 |
Execute a query without reading its results. | |
virtual void | explain (const std::string &query, FILE *out)=0 |
Format and print the EXPLAIN output for the query to the given file. | |
Static Public Member Functions | |
static std::shared_ptr< SQLiteConnection > | create () |
![]() | |
static std::shared_ptr< Connection > | create (const DBConnectOptions &options) |
Create a new connection from a URL. | |
Protected Member Functions | |
void | init_after_connect () |
void | fork_prepare () override |
void | fork_parent () override |
void | fork_child () override |
void | check_connection () |
void | reopen () |
![]() | |
void | register_atfork () |
Register this connection to be notified in case of fork()-ing. | |
virtual void | fork_prepare () |
virtual void | fork_parent () |
virtual void | fork_child () |
Static Protected Member Functions | |
static void | on_sqlite3_profile (void *arg, const char *query, sqlite3_uint64 usecs) |
Protected Attributes | |
std::string | pathname |
Connection pathname. | |
int | flags = 0 |
Connection flags. | |
sqlite3 * | db = nullptr |
Database connection. | |
bool | forked = false |
Marker to catch attempts to reuse connections in forked processes. | |
![]() | |
std::string | url |
Additional Inherited Members | |
![]() | |
ServerType | server_type |
Type of SQL server we are connected to. | |
Database connection.
|
overridevirtual |
Drop the settings table.
Implements dballe::sql::Connection.
|
overridevirtual |
Execute a query without reading its results.
Implements dballe::sql::Connection.
|
overridevirtual |
Format and print the EXPLAIN output for the query to the given file.
Implements dballe::sql::Connection.
|
overrideprotectedvirtual |
Reimplemented from dballe::sql::Connection.
|
overrideprotectedvirtual |
Reimplemented from dballe::sql::Connection.
|
overrideprotectedvirtual |
Reimplemented from dballe::sql::Connection.
int dballe::sql::SQLiteConnection::get_last_insert_id | ( | ) |
Return LAST_INSERT_ID or LAST_INSER_ROWID or whatever is appropriate for the current database, if supported.
If not supported, an exception is thrown.
|
overridevirtual |
Get a value from the settings table.
Returns the empty string if the table does not exist.
Implements dballe::sql::Connection.
|
overridevirtual |
Check if the database contains a table.
Implements dballe::sql::Connection.
|
overridevirtual |
Set a value in the settings table.
The table is created if it does not exist.
Implements dballe::sql::Connection.
|
overridevirtual |
Begin a transaction.
The transaction will be controller by the returned Transaction object, and will end when its destuctor is called.
Implements dballe::sql::Connection.