represents a SQLite3 Database
More...
#include <sl3/database.hpp>
|
sqlite3 * | db () |
| Access the underlying sqlite3 database.
|
|
represents a SQLite3 Database
Encapsulate some/the most - useful methods for a SQLite3 database object.
A Database is opened when a instance is created and close when the instance goes out of scope.
- Note
- for valgrind: http://www.sqlite.org/cvstrac/tktview?tn=3428
since I don't know where to put this note else I place it just here
◆ Callback
◆ Database() [1/2]
sl3::Database::Database |
( |
const std::string & |
name, |
|
|
int |
openFlags = 0 |
|
) |
| |
|
explicit |
Constructor.
Construction of this object opens, or creates a sqlite3 database. The exact behavior can be fine tuned using the openFlags parameter.
- Parameters
-
name | database name.
If name is ":memory:" than the database will be an in memory database.
If name has a size of 0 than the database will be private on disk database.
Otherwise name will be interpreted as a file. |
openFlags | if no flags are given, the defaults are SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE. |
- See also
- https://www.sqlite.org/c3ref/open.html
- Exceptions
-
◆ ~Database()
virtual sl3::Database::~Database |
( |
| ) |
|
|
virtualnoexcept |
◆ Database() [2/2]
◆ beginTransaction()
◆ db()
sqlite3 * sl3::Database::db |
( |
| ) |
|
|
protected |
Access the underlying sqlite3 database.
Derived classes may, if needed, access the pointer to the sqlite3 database.
- Note
- : Do not change the state of database (call close on it).
- Returns
- a handle to the underlying sqlite3 database;
◆ execute() [1/4]
void sl3::Database::execute |
( |
const char * |
sql | ) |
|
Execute one or more SQL statements.
Overload for const char to avoid a copy for larg command like create database scripts which are often static char*
- Exceptions
-
- Parameters
-
◆ execute() [2/4]
void sl3::Database::execute |
( |
const std::string & |
sql | ) |
|
Execute one or more SQL statements.
- Exceptions
-
- Parameters
-
◆ execute() [3/4]
void sl3::Database::execute |
( |
const std::string & |
sql, |
|
|
Callback |
cb |
|
) |
| |
Execute one SQL statements and apply a QueryCallback.
- Exceptions
-
- Parameters
-
sql | SQL Statements |
cb | Callback to handle query result |
◆ execute() [4/4]
void sl3::Database::execute |
( |
const std::string & |
sql, |
|
|
RowCallback & |
cb |
|
) |
| |
Execute one SQL statements and apply a SqlQueryHandler.
- Exceptions
-
- Parameters
-
◆ getLastInsertRowid()
int64_t sl3::Database::getLastInsertRowid |
( |
| ) |
|
returns rowid of the most recent successful INSERT statement
Returns the rowid (ROWID, OID, or ROWID or the column of type INTEGER PRIMARY KEY ) of the most recent successful INSERT into the database.
If no successful INSERTs have ever occurred on that database, zero is returned.
- Returns
- rowid
◆ getMostRecentErrCode()
int sl3::Database::getMostRecentErrCode |
( |
| ) |
|
Returns last SQLite3 extended result code.
- Note
- SQLite3 result code in case of a failure is triggered within a SQLite3Error.
The return value is only valid if the last call failed.
- Note
- This function returns extended result codes
- Returns
- SQLite3 extended error code
◆ getMostRecentErrMsg()
std::string sl3::Database::getMostRecentErrMsg |
( |
| ) |
|
Returns most recent error message.
- Returns
- SQLite3 error message.
◆ getRecentlyChanged()
std::size_t sl3::Database::getRecentlyChanged |
( |
| ) |
|
Rows that have been changed from the most recent SQL statement.
Returns the number of rows that have been changed from the most recent successful SQL INSERT/UPDATE or DELETE statement.
- Returns
- Count of changed rows
◆ getTotalChanges()
std::size_t sl3::Database::getTotalChanges |
( |
| ) |
|
Returns number of row that have changed since database opening.
Returns the number of rows that have been changed Through successful SQL INSERT/UPDATE or DELETE statements since database was opened.
- Returns
- Count of changed rows
◆ prepare() [1/2]
Command sl3::Database::prepare |
( |
const std::string & |
sql | ) |
|
create a SqlCommand instance.
Parameters that the statement might contain will be automatically deduced and created as DbVaraint values
- Parameters
-
- Returns
- a Command instance
◆ prepare() [2/2]
Command sl3::Database::prepare |
( |
const std::string & |
sql, |
|
|
const DbValues & |
params |
|
) |
| |
create a Command.
Given parameters will be used to set up the command parameters,
- Parameters
-
sql | SQL statement |
params | parameters |
- Exceptions
-
- Returns
- a Command instance
◆ select() [1/2]
Dataset sl3::Database::select |
( |
const std::string & |
sql | ) |
|
Execute a SQL query and return the result.
- Exceptions
-
- Parameters
-
- Returns
- a Dataset with the result.
◆ select() [2/2]
Dataset sl3::Database::select |
( |
const std::string & |
sql, |
|
|
const Types & |
types |
|
) |
| |
Execute a SQL query and returns the result .
If Types are
- Exceptions
-
- Parameters
-
sql | SQL Statements |
types | wanted types of the returned Dataset |
- Returns
- a Dataset with the result.
◆ selectValue() [1/2]
DbValue sl3::Database::selectValue |
( |
const std::string & |
sql | ) |
|
Select a single value form the database.
This is a quick way to get single value results for queries like "SELECT COUNT(*) FROM someTable;"
This function returns the first column of the first result row of the given query. If query returns no rows, the return value will be null.
- Exceptions
-
- Parameters
-
- Returns
- DbValue of the first available result.
◆ selectValue() [2/2]
DbValue sl3::Database::selectValue |
( |
const std::string & |
sql, |
|
|
Type |
type |
|
) |
| |
select a single typed value form the database.
This is a quick way to get single value results for queries like "SELECT COUNT(*) FROM someTable;"
This function returns the first column of the first result row of the given query. If query returns no rows, the return value will be null.
- Exceptions
-
- Parameters
-
sql | SQL statement |
type | result has to be of that Type |
- Returns
- DbValue of the first available result.
The documentation for this class was generated from the following file: