glim::SqliteQuery Class Reference

#include <sqlite.hpp>

Inheritance diagram for glim::SqliteQuery:

glim::SqliteParQuery List of all members.

Detailed Description

Wraps the sqlite3_stmt; will prepare it, bind values, query and finalize.


Public Member Functions

 SqliteQuery (SqliteSession *session, char const *query, int queryLength)
 Prepares the query.
 SqliteQuery (SqliteSession *session, std::pair< char const *, int > query)
 Prepares the query.
 SqliteQuery (SqliteSession *session, std::string query)
 Prepares the query.
 ~SqliteQuery ()
 Release resources.
SqliteQueryreset ()
 Call this (followed by the step) if you need the query to be re-executed.
bool next ()
 Synonym for step.
bool step ()
 Invokes sqlite3_step.
SqliteQueryqstep ()
 Perform step and throw an exception if step has returned false.
int ustep ()
 Invokes a DML query and returns the number of rows affected.
int changes ()
 The number of rows changed by the query.
int intAt (int column)
 The integer value of the given column.
int64_t int64at (int column)
 The integer value of the given column.
double doubleAt (int column)
 The floating point number from the given column.
std::pair< char const *, int > charsAt (int column)
 Return the column as UTF-8 characters, which can be used until the next step.
std::string stringAt (int column)
 Return the column as C++ string (UTF-8).
int typeAt (int column)
 The type of the column.
template<typename T>
SqliteQueryoperator<< (T value)
 Binds a value using one of the bind methods.
template<typename T>
SqliteQuerybind (char const *name, T value)
 Binds a value using the named parameter and one of the bind methods.
SqliteQuerybind (int index, const char *text, int length, bool transient=false)
 Bind a string to the query.
SqliteQuerybind (int index, std::pair< const char *, int > text, bool transient=false)
 Bind a string to the query.
SqliteQuerybind (int index, std::string text, bool transient=true)
 Bind a string to the query.
SqliteQuerybind (int index, int value)
 Bind an integer to the query.
SqliteQuerybind (int index, long long int value)
 Bind an 64-bit integer to the query.

Protected Member Functions

void prepare (SqliteSession *session, char const *query, int queryLength)

Protected Attributes

::sqlite3_stmt * statement
SqliteSessionsession
int bindCounter
int mChanges
 -1 if statement isn't DONE.


Constructor & Destructor Documentation

glim::SqliteQuery::SqliteQuery SqliteSession session,
char const *  query,
int  queryLength
[inline]
 

Prepares the query.

Exceptions:
std::runtime_error if sqlite3_prepare fails; format of the error message is "$query: $errmsg".

glim::SqliteQuery::SqliteQuery SqliteSession session,
std::pair< char const *, int >  query
[inline]
 

Prepares the query.

Exceptions:
std::runtime_error if sqlite3_prepare fails; format of the error message is "$query: $errmsg".

glim::SqliteQuery::SqliteQuery SqliteSession session,
std::string  query
[inline]
 

Prepares the query.

Exceptions:
std::runtime_error if sqlite3_prepare fails; format of the error message is "$query: $errmsg".

glim::SqliteQuery::~SqliteQuery  )  [inline]
 

Release resources.

See also:
http://sqlite.org/capi3ref.html#sqlite3_finalize


Member Function Documentation

SqliteQuery& glim::SqliteQuery::bind int  index,
std::string  text,
bool  transient = true
[inline]
 

Bind a string to the query.

Parameters:
transient must be true, if lifetime of the string might be shorter than that of the query.

SqliteQuery& glim::SqliteQuery::bind int  index,
std::pair< const char *, int >  text,
bool  transient = false
[inline]
 

Bind a string to the query.

Parameters:
transient must be true, if lifetime of the string might be shorter than that of the query.

SqliteQuery& glim::SqliteQuery::bind int  index,
const char *  text,
int  length,
bool  transient = false
[inline]
 

Bind a string to the query.

Parameters:
transient must be true, if lifetime of the string might be shorter than that of the query.

template<typename T>
SqliteQuery& glim::SqliteQuery::bind char const *  name,
value
[inline]
 

Binds a value using the named parameter and one of the bind methods.

Exceptions:
std::runtime_error if the name could not be found.
See also:
http://sqlite.org/capi3ref.html#sqlite3_bind_parameter_index

int glim::SqliteQuery::changes  )  [inline]
 

The number of rows changed by the query.

Providing the query was a DML (Data Modification Language), returns the number of rows updated.
If the query wasn't a DML, returned value is undefined.
-1 is returned if the query wasn't executed, or after reset.
Example:

 SqliteQuery query (&ses, S("update test set count = count + ? where id = ?"));
 query.bind (1, 1);
 query.bind (2, 9);
 query.step ();
 int affected = query.changes ();
See also:
ustep

std::pair<char const*, int> glim::SqliteQuery::charsAt int  column  )  [inline]
 

Return the column as UTF-8 characters, which can be used until the next step.

Parameters:
column 1-based.
See also:
http://sqlite.org/capi3ref.html#sqlite3_column_text

double glim::SqliteQuery::doubleAt int  column  )  [inline]
 

The floating point number from the given column.

Parameters:
column 1-based.
See also:
http://sqlite.org/capi3ref.html#sqlite3_column_text

int64_t glim::SqliteQuery::int64at int  column  )  [inline]
 

The integer value of the given column.

Parameters:
column 1-based.
See also:
http://sqlite.org/capi3ref.html#sqlite3_column_text

int glim::SqliteQuery::intAt int  column  )  [inline]
 

The integer value of the given column.

Parameters:
column 1-based.
See also:
http://sqlite.org/capi3ref.html#sqlite3_column_text

SqliteQuery& glim::SqliteQuery::qstep  )  [inline]
 

Perform step and throw an exception if step has returned false.

Usage example:

 (ses.query(S("select count(*) from test where idx = ?")) << 12345).qstep().intAt(1) 

SqliteQuery& glim::SqliteQuery::reset  )  [inline]
 

Call this (followed by the step) if you need the query to be re-executed.

See also:
http://sqlite.org/capi3ref.html#sqlite3_reset

bool glim::SqliteQuery::step  )  [inline]
 

Invokes sqlite3_step.

Returns:
true if there was a row fetched successfully, false if there is no more rows.
See also:
http://sqlite.org/capi3ref.html#sqlite3_step

Reimplemented in glim::SqliteParQuery.

std::string glim::SqliteQuery::stringAt int  column  )  [inline]
 

Return the column as C++ string (UTF-8).

Parameters:
column 1-based.

int glim::SqliteQuery::typeAt int  column  )  [inline]
 

The type of the column.

SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB or SQLITE_NULL.

Parameters:
column 1-based.
See also:
http://sqlite.org/capi3ref.html#sqlite3_column_text

int glim::SqliteQuery::ustep  )  [inline]
 

Invokes a DML query and returns the number of rows affected.

Example:

 int affected = (ses.query(S("update test set count = count + ? where id = ?")) << 1 << 9).ustep();
See also:
http://sqlite.org/capi3ref.html#sqlite3_step


Generated on Fri Nov 24 20:57:37 2006 for libglim by  doxygen 1.4.6