This repository was archived by the owner on May 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Database
Nicuvëo edited this page Mar 29, 2014
·
5 revisions
A Database object is a wrapper around a raw sqlite3* pointer. The pointer is stored in a boost::shared_ptr, making Databases instances flyweight and copyable. When the last Database object owning a given sqlite3* pointer is deleted, the connection is closed.
--
| Name | Description |
|---|---|
| Database() | Constructs an empty database object. |
| Database(const char* filename) | Constructs a new database / opens an existing database. |
--
| Name | Description |
|---|---|
| bool connected() const | Answers whether the given instance is connected to a real database. |
| Statement make(const char* query) const | Prepares a statement from the given query. |
| sqlite3* raw_data() const | Access the underlying raw sqlite3* pointer. |
Notes:
-
db.connected()is equivalent todb.raw_data() != 0. - The
raw_datapointer is not meant to be stored and used outside of theDatabaseinstance, as its lifetime is managed via reference counting in the instance itself.
--
| Name | Description |
|---|---|
| void connect(const char* filename) | Constructs a new database / opens an existing database. |
| void disconnect() | Disconnects the instance from its current database if any. |
--
| Name | Description |
|---|---|
| Rows exec(const char* q) const | Execute a query -> rows |
| Rows exec(const char* q, const Parameters& ps) const | Execute a query -> rows |
| void exec(const char* q, const RowCallback& cb) const | Execute a query, callback on each row. |
| void exec(const char* q, const RowCallback& cb, const Parameters& ps) const | Execute a query, callback on each row. |
| RowRange result(const char* q) const | Execute a query -> row range. |
| RowRange result(const char* q, const Parameters& ps) const | Execute a query -> row range. |
Notes:
-
Rowsstore the whole query result in memory, whileRowRangeallows you to iterate on the results one database row at a time. - Use the provided
saw_foreachmacro to iterate on aRowRange:
saw_foreach (const Row& r, db.result("select * from clients"))
{
// do something with r
}- Variants with a
Parametersargument will perform parameter substitution.