1#ifndef s11n_net_SQLITE3X_HPP_INCLUDED
2#define s11n_net_SQLITE3X_HPP_INCLUDED
94#ifndef SQLITE3X_USE_WCHAR
95# ifdef _GLIBCXX_USE_WCHAR_T
96# define SQLITE3X_USE_WCHAR 1
97# elif defined(UNICODE)
98# define SQLITE3X_USE_WCHAR 1
100# define SQLITE3X_USE_WCHAR 0
157 mutable struct sqlite3 *m_db;
172 sqlite3 *
db()
const;
205 std::string
name()
const;
231 virtual void open(
char const * );
236 void open(std::string
const &dbname);
259 void take( sqlite3 * dbh );
266 sqlite3 *
take()
throw();
376 int executecallback( std::string
const & sql, sqlite3_callback callback,
void * data, std::string & errmsg );
383 int executecallback( std::string
const & sql, sqlite3_callback callback,
void * data = 0 );
394#if SQLITE3X_USE_WCHAR
402 std::wstring executestring16(
const std::wstring &sql);
403 std::wstring executestring16(
const std::string &sql);
405 void open(
const wchar_t *dbname);
557 char const *
getstring(
int index,
int & size);
563 std::string
getblob(
int index);
571 void const *
getblob(
int index,
int & size );
581#if SQLITE3X_USE_WCHAR
582 std::wstring getstring16(
int index);
583 std::wstring getcolname16(
int index);
600 mutable sqlite3_stmt *stmt;
632 void prepare(
char const * sql,
int len = -1 );
636 void prepare( std::string
const & sql );
641 void bind(
int index);
645 void bind(
int index,
int data);
653 void bind(
int index,
double data);
659 void bind(
int index,
const char *data,
int datalen = -1);
665 void bind(
int index,
const void *data,
int datalen);
669 void bind(
int index,
const std::string &data);
764#if SQLITE3X_USE_WCHAR
766 void bind(
int index,
const wchar_t *data,
int datalen);
767 void bind(
int index,
const std::wstring &data);
768 std::wstring executestring16();
798 virtual char const *
what()
const throw();
Exception type used by the sqlite3x classes.
database_error(const char *format,...)
Takes a format specifier compatible with printf.
virtual char const * what() const
Returns this object's error string.
Encapsulates a command to send to an sqlite3_connection.
int executeint()
Executes the query, which is expected to have an integer field as the first result field.
~sqlite3_command()
Cleans up any resources in use by this object.
bool reset()
Resets this statement using sqlite3_reset().
void executenonquery()
Executes the query and provides no way to get the results.
std::string executeblob()
Executes the query, which is expected to have a string or blob field as the first result field.
void prepare(char const *sql, int len=-1)
Prepares this statement or throws on error.
void finalize()
Finalizes this statement.
int colcount()
Returns the column count of this object's query, or throws on error.
sqlite3_cursor executecursor()
Executes the query and returns a cursor object which can be used to iterate over the results.
double executedouble()
Executes the query, which is expected to have a double field as the first result field.
std::string executestring()
Executes the query, which is expected to have a string or blob field as the first result field.
int64_t executeint64()
Executes the query, which is expected to have a (int64_t) field as the first result field.
sqlite3_stmt * handle()
Returns the underlying statement handle.
void bind(int index)
Binds NULL to the given index.
Represents a connection to an sqlite3 database.
void close()
Closes this database.
sqlite3_connection()
Default ctor.
sqlite3 * db() const
Returns a handle to the underlying sqlite3 database.
void executenonquery(const std::string &sql)
Executes a command which is assumed to have a single step and a void result.
virtual void open(char const *)
Creates/opens the given db, throwing on error.
int64_t executeint64(const std::string &sql)
Executes the query, which is expected to have a (int64_t) field as the first result field.
int64_t insertid()
Returns the rowid of the most recently inserted row on this db.
std::string name() const
Returns this object's name.
int changes()
Returns the number of database rows that were changed (or inserted or deleted) by the most recently c...
sqlite3 * take()
Transfers ownership of the returned handle to the caller.
virtual ~sqlite3_connection()
Calls this->close() if close() has not already been called.
std::string executeblob(const std::string &sql)
Executes the query, which is expected to have a string or blob field as the first result field.
double executedouble(const std::string &sql)
Executes the query, which is expected to have a double field as the first result field.
int executecallback(std::string const &sql, sqlite3_callback callback, void *data, std::string &errmsg)
Executes the given SQL code, calling callback for each row of the data set.
void setbusytimeout(int ms)
See sqlite3_busy_timeout().
std::string executestring(const std::string &sql)
Executes the query, which is expected to have a string or blob field as the first result field.
std::string errormsg() const
Returns the equivalent of sqlite3_errmsg(), or an empty string if that function returns null.
virtual void on_open()
This function is called when open() succeeds.
int executeint(const std::string &sql)
Executes the query, which is expected to have an integer field as the first result field.
A type for reading results from an sqlite3_command.
int getint(int index)
Gets the integer value at the given field number.
int64_t getint64(int index)
Gets the (int64_t) value at the given field number.
std::string getstring(int index)
Gets the string value at the given field number.
sqlite3_cursor()
Creates an empty cursor object, suitable only for use as the target of a copy/assignment.
void close()
Closes this cursor.
bool isnull(int index)
Check if the given field number is NULL.
~sqlite3_cursor()
Closes this cursor, freeing up db resources if this is the last cursor of a copied set.
int colcount()
Returns the column count of the result set or throws on error.
std::string getcolname(int index)
Gets the column name for the given column index.
bool step()
Steps one step through the sql result set and returns true on SQLITE_ROW, false on SQLITE3_DONE,...
sqlite3_cursor & operator=(const sqlite3_cursor ©)
Copies the given cursor object.
void reset()
Resets the underlying prepared statement of this cursor.
std::string getblob(int index)
Gets the blob value at the given field number.
double getdouble(int index)
Gets the double value at the given field number.
Manages an sqlite3 transaction.
~sqlite3_transaction()
If destructed before commit() is called, rollback() is called.
void begin()
Starts a transaction.
void commit()
Commits a transaction.
void rollback()
Rolls back a transaction with a commit.
An internal implementation detail of table_generator.
table_generator(sqlite3_connection &con, std::string const &name)
Initializes the table generation process.
~table_generator()
Frees up internal resources.
void create()
Executes the 'create table' statements.
table_generator & operator()(std::string const &field_name)
Adds field_name as a field of this table.
This namespace encapsulates a C++ API wrapper for sqlite3 databases.
sqlite_int64 int64_t
64-bit integer type used by this code.
bool rc_is_okay(int rc)
rc_is_okay() is an easy way to check if rc is one of SQLITE_OK, SQLITE_ROW, or SQLITE_DONE.