MLIB
|
Wrapper for database connection handle. More...
#include <sqlitepp.h>
Public Types | |
enum class | openflags { readonly = SQLITE_OPEN_READONLY , readwrite = SQLITE_OPEN_READWRITE , create = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE , uri = SQLITE_OPEN_URI , nomutex = SQLITE_OPEN_NOMUTEX , fullmutex = SQLITE_OPEN_FULLMUTEX , sharedcache = SQLITE_OPEN_SHAREDCACHE , privatecache = SQLITE_OPEN_PRIVATECACHE , memory = SQLITE_OPEN_MEMORY | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE , nofollow = SQLITE_OPEN_NOFOLLOW , ext_result = SQLITE_OPEN_EXRESCODE } |
Flags for database opening mode. More... | |
Public Member Functions | |
Database () | |
Default constructor. | |
Database (const std::string &name, openflags flags=openflags::create) | |
Open a database specified by name. | |
Database & | copy (Database &src) |
Copy database content. | |
bool | connected () |
Check if database is opened or not. | |
bool | is_readonly () |
Return true if database connection is read-only. | |
operator sqlite3 * () | |
Return handle of database connection. | |
sqlite3 * | handle () const |
Return handle of database connection. | |
sqlite3_int64 | last_rowid () |
Return rowid of last successful insert. | |
sqlite3_int64 | changes () |
Return number of records changed by last query. | |
sqlite3_int64 | total_changes () |
Return total number of changes since database was opened. | |
erc | open (const std::string &name, openflags flags=openflags::create) |
Open database connection. | |
erc | close () |
Close database connection. | |
erc | exec (const std::string &sql) |
Execute multiple SQL sentences. | |
checked< Query > | make_query (const std::string &sql) |
Return a Query object containing a prepared statement with the given SQL text. | |
checked< Query > | make_query_multiple (std::string &sql) |
Return a Query object containing the first prepared statement of the given SQL text. | |
std::string | filename (const std::string &schema="main") const |
Return filename of a database connection. | |
std::string | schema (int n) const |
Return schema name for a database connection. | |
int | extended_error () |
Return extended result code. | |
erc | flush () |
Flush. | |
Static Public Member Functions | |
static void | Errors (mlib::errfac &fac) |
Set error facility for all SQLITEPP errors. | |
static const errfac & | Errors () |
Return error facility used by SQLITEPP. | |
Friends | |
class | Query |
Wrapper for database connection handle.
The Database class is a wrapper around the sqlite3 handle returned by sqlite_open_v2 function.
|
strong |
Flags for database opening mode.
mlib::Database::Database | ( | ) |
Default constructor.
The default constructor is used to create an object that is not yet connected to a database.
It has to be connected using the open() function.
mlib::Database::Database | ( | const std::string & | name, |
openflags | flags = openflags::create |
||
) |
Open a database specified by name.
name | database name |
flags | open flags |
Copy database content.
Perform a copy operation using the SQLITE Backup API.
Both databases should be opened.
string mlib::Database::filename | ( | const std::string & | schema = "main" | ) | const |
Return filename of a database connection.
Return an empty string if database is not opened or there is no database connection with that name or if the database is a temporary or in-memory database.
Otherwise returns the filename of the database that was attached using an SQL ATTACH statement.
bool mlib::Database::is_readonly | ( | ) |
Return true if database connection is read-only.
Returns FALSE only for connected read-write databases.
If database is not connected or it is read-only, returns TRUE.
checked< Query > mlib::Database::make_query | ( | const std::string & | sql | ) |
checked< Query > mlib::Database::make_query_multiple | ( | std::string & | sql | ) |
Return a Query object containing the first prepared statement of the given SQL text.
This function compiles only the first statement in the sql
string.
It updates sql
string with what's left after the end of the query.
erc mlib::Database::open | ( | const std::string & | name, |
openflags | flags = openflags::create |
||
) |
Open database connection.
If the object is associated with another connection, the previous connection is closed and a new one is opened.
name | Database name |
flags | Combination of openflags flags |
std::string mlib::Database::schema | ( | int | n | ) | const |
Return schema name for a database connection.