+
This binders use variables as parameters for SQL queries. Following code
-uses variable id to select column name from table employees:
+uses variable id to select column
name from table
employees:
session db("test.db");
statement st(db);
@@ -719,8 +740,8 @@
-
+
+
Query is a noncopyable collection of SQL text and variable binders:
// Query class. Noncopyable
@@ -848,8 +869,9 @@
diff --git a/doc/sqlitepp.rst b/doc/sqlitepp.rst
index 17a45b4..42250b9 100644
--- a/doc/sqlitepp.rst
+++ b/doc/sqlitepp.rst
@@ -7,9 +7,7 @@ C++ wrapper to SQLite library
:Author: Pavel Medvedev
:Contact: pmedvedev@gmail.com
-:date: $Date$
-:revision: $Rev$
-:copyright: Copyright (c) 2004-2008 Pavel Medvedev
+:copyright: Copyright (c) 2004-2012 Pavel Medvedev
.. contents:: Table of Contents
.. section-numbering::
@@ -202,7 +200,8 @@ Next example.
use(e.name), use(e.age), use(e.salary);
while ( std::cin >> e )
{
- st.exec(); // **(1.1)**
+ st.reset(true); // **(1.1)**
+ st.exec(); // **(1.2)**
}
// **(2)**
@@ -226,8 +225,10 @@ Again usual things happen - we create session and table. Then we create
statement object ``st``. It is executing in context of database ``db``. In the
code block marked as (1) we prepare SQL query and bind variable e members to
SQL values(:name, :age, :salary) of the same name. Next, in loop we ask user
-to enter employee data. In line marked (1.1) the statement is executed and
-data of members``e`` are inserted into the table ``employee``.
+to enter employee data. At line (1.1) the statement is reset after previous
+execution step and use values for ``e`` are rebound. At the next line (1.2)
+the statement is executed and data of members``e`` are inserted into
+the table ``employee``.
But let's check contents of the ``employee``. The code block marked as (2)
demonstrates it. Statement ``st`` is preparing with new SQL select query. Note
@@ -387,13 +388,17 @@ Session is a SQLite database abstraction::
session();
// Create and open session.
- explicit session(string_t const& file_name);
-
+ // Optional parameter flags for file open operations
+ // (see SQLite reference at http://sqlite.org/c3ref/c_open_autoproxy.html)
+ explicit session(string_t const& file_name, int flags = 0);
+
// Close session on destroy.
~session();
// Open database session. Previous one will be closed.
- void open(string_t const& file_name);
+ // Optional parameter flags for file open operations
+ // (see SQLite reference at http://sqlite.org/c3ref/c_open_autoproxy.html)
+ void open(string_t const& file_name, int flags = 0);
// Close database session.
void close();
@@ -407,17 +412,30 @@ Session is a SQLite database abstraction::
// If we have the transaction, we get it or null otherwise.
transaction* active_txn() const; // throw()
- // Last insert row ID
+ /// SQLite implementation for native sqlite3 functions.
+ sqlite3* impl() const;
+
+ /// Check error code. If code is not ok, throws exception.
+ void check_error(int code) const;
+ void check_last_error() const;
+
+ // Last session error
+ int last_error() const;
+
+ // Last statement::exec result
+ bool last_exec() const;
+
+ // Last insert row ID
long long last_insert_rowid() const;
- // The number of rows that were changed (or inserted or deleted)
- // by the most recent SQL statement
- size_t last_changes() const;
-
- // The number of rows that were changed (or inserted or deleted)
- // since the database was opened
- size_t total_changes() const;
-
+ // The number of rows that were changed (or inserted or deleted)
+ // by the most recent SQL statement
+ size_t last_changes() const;
+
+ // The number of rows that were changed (or inserted or deleted)
+ // since the database was opened
+ size_t total_changes() const;
+
// Execute SQL query immediately.
// It might be useful for resultless statements like INSERT, UPDATE etc.
// T is any output-stream-shiftable type.
@@ -425,7 +443,7 @@ Session is a SQLite database abstraction::
once_query operator<<(T const& t);
// Swap session instances
- friend void swap(session& lhs, session& rhs);
+ friend void swap(session& lhs, session& rhs);
};
Statement
@@ -455,6 +473,9 @@ Database statement::
// Finalize statement.
void finalize();
+ /// SQLite statement implementation for sqlite3 functions
+ sqlite3_stmt* impl() const;
+
// Is statement prepared.
bool is_prepared() const; // throw()
@@ -537,8 +558,11 @@ You should call ``transaction::commit`` to explicitly make a commit. ::
class transaction
{
public:
- // Begin transaction in context of the session s.
- transaction(session& s);
+ // Transaction type
+ enum type { deferred, immediate, exclusive };
+
+ // Begin transaction in context of session.
+ transaction(session& s, type t = deferred);
// End transaction with rollback if it is not commited.
~transaction();
@@ -554,11 +578,11 @@ BLOB
SQLite tables can contain BLOB columns. BLOB is a simple struct::
- struct blob
- {
- void const* data; // raw data pointer
- size_t size; // data size in bytes
- };
+ struct blob
+ {
+ void const* data; // raw data pointer
+ size_t size; // data size in bytes
+ };
SQLite++ supports conversion between template ``std::vector
`` and blob value.
See "Data Conversion" section below.
diff --git a/examples/ex2.cpp b/examples/ex2.cpp
index f41b666..37591cc 100644
--- a/examples/ex2.cpp
+++ b/examples/ex2.cpp
@@ -40,7 +40,8 @@ int main()
, use(e.name), use(e.age), use(e.salary);
while ( std::cin >> e )
{
- st.exec(); // (1.1)
+ st.reset(true); // (1.1)
+ st.exec(); // (1.2)
}
// (2)