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