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) // Windows uses this
98 # define SQLITE3X_USE_WCHAR 1
100 # define SQLITE3X_USE_WCHAR 0 // default
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();
769 #endif // SQLITE3_USE_WCHAR
798 virtual char const *
what()
const throw();
916 #endif // s11n_net_SQLITE3X_HPP_INCLUDED
Manages an sqlite3 transaction.
void begin()
Starts a transaction.
void create()
Executes the 'create table' statements.
An internal implementation detail of table_generator.
void finalize()
Finalizes this statement.
table_generator & operator()(std::string const &field_name)
Adds field_name as a field of this table.
void setbusytimeout(int ms)
See sqlite3_busy_timeout().
sqlite_int64 int64_t
64-bit integer type used by this code.
void executenonquery(const std::string &sql)
Executes a command which is assumed to have a single step and a void result.
virtual void on_open()
This function is called when open() succeeds.
virtual ~sqlite3_connection()
Calls this->close() if close() has not already been called.
std::string getblob(int index)
Gets the blob value at the given field number.
std::string name() const
Returns this object's name.
std::string executestring()
Executes the query, which is expected to have a string or blob field as the first result field.
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.
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.
sqlite3_cursor executecursor()
Executes the query and returns a cursor object which can be used to iterate over the results.
database_error(const char *format,...)
Takes a format specifier compatible with printf.
sqlite3_connection()
Default ctor.
~sqlite3_cursor()
Closes this cursor, freeing up db resources if this is the last cursor of a copied set.
sqlite3_cursor & operator=(const sqlite3_cursor ©)
Copies the given cursor object.
int colcount()
Returns the column count of this object's query, or throws on error.
int executeint()
Executes the query, which is expected to have an integer field as the first result field.
void commit()
Commits a transaction.
int changes()
Returns the number of database rows that were changed (or inserted or deleted) by the most recently c...
std::string errormsg() const
Returns the equivalent of sqlite3_errmsg(), or an empty string if that function returns null.
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.
virtual char const * what() const
Returns this object's error string.
int64_t getint64(int index)
Gets the (int64_t) value at the given field number.
~table_generator()
Frees up internal resources.
bool reset()
Resets this statement using sqlite3_reset().
A helper class to generate db tables.
int64_t executeint64()
Executes the query, which is expected to have a (int64_t) field as the first result field.
bool step()
Steps one step through the sql result set and returns true on SQLITE_ROW, false on SQLITE3_DONE,...
void executenonquery()
Executes the query and provides no way to get the results.
virtual void open(char const *)
Creates/opens the given db, throwing on error.
This namespace encapsulates a C++ API wrapper for sqlite3 databases.
~sqlite3_command()
Cleans up any resources in use by this object.
int getint(int index)
Gets the integer value at the given field number.
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.
Represents a connection to an sqlite3 database.
void bind(int index)
Binds NULL to the given index.
table_generator(sqlite3_connection &con, std::string const &name)
Initializes the table generation process.
std::string executeblob()
Executes the query, which is expected to have a string or blob field as the first result field.
double executedouble()
Executes the query, which is expected to have a double field as the first result field.
void prepare(char const *sql, int len=-1)
Prepares this statement or throws on error.
sqlite3_cursor()
Creates an empty cursor object, suitable only for use as the target of a copy/assignment.
double getdouble(int index)
Gets the double value at the given field number.
void close()
Closes this cursor.
sqlite3 * db() const
Returns a handle to the underlying sqlite3 database.
double executedouble(const std::string &sql)
Executes the query, which is expected to have a double field as the first result field.
int64_t executeint64(const std::string &sql)
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.
Exception type used by the sqlite3x classes.
void close()
Closes this database.
Encapsulates a command to send to an sqlite3_connection.
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.
int colcount()
Returns the column count of the result set or throws on error.
~sqlite3_transaction()
If destructed before commit() is called, rollback() is called.
std::string getcolname(int index)
Gets the column name for the given column index.
int64_t insertid()
Returns the rowid of the most recently inserted row on this db.
sqlite3 * take()
Transfers ownership of the returned handle to the caller.
bool isnull(int index)
Check if the given field number is NULL.
void rollback()
Rolls back a transaction with a commit.
void reset()
Resets the underlying prepared statement of this cursor.
std::string getstring(int index)
Gets the string value at the given field number.