libsqlite3x 2007.10.18
|
Encapsulates a command to send to an sqlite3_connection. More...
#include <sqlite3x.hpp>
Public Member Functions | |
sqlite3_command (sqlite3_connection &con) | |
Creates an unprepared statement. | |
sqlite3_command (sqlite3_connection &con, const std::string &sql) | |
Creates an sql statement with the given connection object and sql code. | |
sqlite3_command (sqlite3_connection &con, char const *sql, size_t len) | |
An efficiency overload to avoid an extra copy of the sql code. | |
~sqlite3_command () | |
Cleans up any resources in use by this object. | |
void | prepare (char const *sql, int len=-1) |
Prepares this statement or throws on error. | |
void | prepare (std::string const &sql) |
Convenience overload taking a std::string. | |
void | bind (int index) |
Binds NULL to the given index. | |
void | bind (int index, int data) |
Binds data to the given query index. | |
void | bind (int index, int64_t data) |
Binds data to the given query index. | |
void | bind (int index, double data) |
Binds data to the given query index. | |
void | bind (int index, const char *data, int datalen=-1) |
Binds data to the given query index. | |
void | bind (int index, const void *data, int datalen) |
Binds data to the given query index. | |
void | bind (int index, const std::string &data) |
Binds data to the given query index. | |
sqlite3_cursor | executecursor () |
Executes the query and returns a cursor object which can be used to iterate over the results. | |
void | executenonquery () |
Executes the query and provides no way to get the results. | |
int | executeint () |
Executes the query, which is expected to have an integer 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. | |
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. | |
char const * | executestring (int &size) |
Like executestring(), but returns a C-style string. | |
std::string | executeblob () |
Executes the query, which is expected to have a string or blob field as the first result field. | |
void const * | executeblob (int &size) |
Like executeblob(), but returns a void pointer to the data. | |
int | colcount () |
Returns the column count of this object's query, or throws on error. | |
bool | reset () |
Resets this statement using sqlite3_reset(). | |
sqlite3_stmt * | handle () |
Returns the underlying statement handle. | |
void | finalize () |
Finalizes this statement. | |
Friends | |
class | sqlite3_cursor |
Encapsulates a command to send to an sqlite3_connection.
Definition at line 592 of file sqlite3x.hpp.
|
explicit |
Creates an unprepared statement.
Use prepare() create the statement.
Definition at line 29 of file sqlite3x_command.cpp.
sqlite3x::sqlite3_command::sqlite3_command | ( | sqlite3_connection & | con, |
const std::string & | sql ) |
Creates an sql statement with the given connection object and sql code.
Definition at line 35 of file sqlite3x_command.cpp.
References prepare().
sqlite3x::sqlite3_command::sqlite3_command | ( | sqlite3_connection & | con, |
char const * | sql, | ||
size_t | len ) |
An efficiency overload to avoid an extra copy of the sql code.
len must be the length of sql.
Definition at line 41 of file sqlite3x_command.cpp.
References prepare().
sqlite3x::sqlite3_command::~sqlite3_command | ( | ) |
Cleans up any resources in use by this object.
Definition at line 91 of file sqlite3x_command.cpp.
References finalize().
void sqlite3x::sqlite3_command::bind | ( | int | index | ) |
Binds NULL to the given index.
Definition at line 113 of file sqlite3x_command.cpp.
Referenced by sqlite3x::settings_db::get(), sqlite3x::settings_db::get(), sqlite3x::settings_db::get(), sqlite3x::settings_db::get(), sqlite3x::settings_db::get(), sqlite3x::settings_db::set(), sqlite3x::settings_db::set(), sqlite3x::settings_db::set(), sqlite3x::settings_db::set(), sqlite3x::settings_db::set(), and sqlite3x::settings_db::set().
void sqlite3x::sqlite3_command::bind | ( | int | index, |
const char * | data, | ||
int | datalen = -1 ) |
Binds data to the given query index.
Data must be exactly datalen bytes long. If datalen == -1 then strlen(data) is used to calculate it.
Definition at line 133 of file sqlite3x_command.cpp.
void sqlite3x::sqlite3_command::bind | ( | int | index, |
const std::string & | data ) |
Binds data to the given query index.
Definition at line 156 of file sqlite3x_command.cpp.
void sqlite3x::sqlite3_command::bind | ( | int | index, |
const void * | data, | ||
int | datalen ) |
Binds data to the given query index.
Data must be exactly datalen bytes long.
Definition at line 151 of file sqlite3x_command.cpp.
void sqlite3x::sqlite3_command::bind | ( | int | index, |
double | data ) |
Binds data to the given query index.
Definition at line 128 of file sqlite3x_command.cpp.
void sqlite3x::sqlite3_command::bind | ( | int | index, |
int | data ) |
Binds data to the given query index.
Definition at line 118 of file sqlite3x_command.cpp.
void sqlite3x::sqlite3_command::bind | ( | int | index, |
int64_t | data ) |
Binds data to the given query index.
Definition at line 123 of file sqlite3x_command.cpp.
int sqlite3x::sqlite3_command::colcount | ( | ) |
Returns the column count of this object's query, or throws on error.
Definition at line 226 of file sqlite3x_command.cpp.
Referenced by sqlite3x::sqlite3_cursor::colcount().
std::string sqlite3x::sqlite3_command::executeblob | ( | ) |
Executes the query, which is expected to have a string or blob field as the first result field.
Note that numeric results can be returned using this function, but will come back as a string (lexically cast).
Definition at line 214 of file sqlite3x_command.cpp.
References executecursor(), sqlite3x::sqlite3_cursor::getblob(), and sqlite3x::sqlite3_cursor::step().
Referenced by sqlite3x::sqlite3_connection::executeblob().
void const * sqlite3x::sqlite3_command::executeblob | ( | int & | size | ) |
Like executeblob(), but returns a void pointer to the data.
size is set to the length of the returned data.
The advantage of this over executeblob() is that this version avoids a potential extra internal copy of the string and "should work" on wide-char strings. Note that there is no guaranty how long this pointer will remain valid - be sure to copy it if you need it for very long.
Definition at line 220 of file sqlite3x_command.cpp.
References executecursor(), sqlite3x::sqlite3_cursor::getblob(), and sqlite3x::sqlite3_cursor::step().
sqlite3_cursor sqlite3x::sqlite3_command::executecursor | ( | ) |
Executes the query and returns a cursor object which can be used to iterate over the results.
Definition at line 168 of file sqlite3x_command.cpp.
Referenced by executeblob(), executeblob(), executedouble(), executeint(), executeint64(), executenonquery(), executestring(), and executestring().
double sqlite3x::sqlite3_command::executedouble | ( | ) |
Executes the query, which is expected to have a double field as the first result field.
Definition at line 188 of file sqlite3x_command.cpp.
References executecursor(), sqlite3x::sqlite3_cursor::getdouble(), and sqlite3x::sqlite3_cursor::step().
Referenced by sqlite3x::sqlite3_connection::executedouble(), and sqlite3x::settings_db::get().
int sqlite3x::sqlite3_command::executeint | ( | ) |
Executes the query, which is expected to have an integer field as the first result field.
Definition at line 176 of file sqlite3x_command.cpp.
References executecursor(), sqlite3x::sqlite3_cursor::getint(), and sqlite3x::sqlite3_cursor::step().
Referenced by sqlite3x::sqlite3_connection::executeint(), sqlite3x::settings_db::get(), and sqlite3x::settings_db::get().
int64_t sqlite3x::sqlite3_command::executeint64 | ( | ) |
Executes the query, which is expected to have a (int64_t) field as the first result field.
Definition at line 182 of file sqlite3x_command.cpp.
References executecursor(), sqlite3x::sqlite3_cursor::getint64(), and sqlite3x::sqlite3_cursor::step().
Referenced by sqlite3x::sqlite3_connection::executeint64(), and sqlite3x::settings_db::get().
void sqlite3x::sqlite3_command::executenonquery | ( | ) |
Executes the query and provides no way to get the results.
Throws on error.
Definition at line 172 of file sqlite3x_command.cpp.
References executecursor(), and sqlite3x::sqlite3_cursor::step().
Referenced by sqlite3x::sqlite3_connection::executenonquery(), sqlite3x::settings_db::set(), sqlite3x::settings_db::set(), sqlite3x::settings_db::set(), sqlite3x::settings_db::set(), sqlite3x::settings_db::set(), and sqlite3x::settings_db::set().
std::string sqlite3x::sqlite3_command::executestring | ( | ) |
Executes the query, which is expected to have a string or blob field as the first result field.
Note that numeric results can be returned using this function, but will come back as a string (lexically cast).
Definition at line 200 of file sqlite3x_command.cpp.
References executecursor(), sqlite3x::sqlite3_cursor::getstring(), and sqlite3x::sqlite3_cursor::step().
Referenced by sqlite3x::sqlite3_connection::executestring(), and sqlite3x::settings_db::get().
char const * sqlite3x::sqlite3_command::executestring | ( | int & | size | ) |
Like executestring(), but returns a C-style string.
We hope it is null-terminated, but the sqlite3 docs are ambiguous on this point. size is set to the length of the returned string.
The advantage of this over executestring() is that this version avoids a potential extra internal copy of the string. Note that there is no guaranty how long this pointer will remain valid - be sure to copy the string if you need it.
Definition at line 194 of file sqlite3x_command.cpp.
References executecursor(), sqlite3x::sqlite3_cursor::getstring(), and sqlite3x::sqlite3_cursor::step().
void sqlite3x::sqlite3_command::finalize | ( | ) |
Finalizes this statement.
Throws if finalization fails. Calling finalize() multiple times is a no-op.
Definition at line 103 of file sqlite3x_command.cpp.
Referenced by prepare(), and ~sqlite3_command().
sqlite3_stmt * sqlite3x::sqlite3_command::handle | ( | ) |
Returns the underlying statement handle.
It is not legal to finalize this statement handle, as that will put this object out of sync with the state of the handle.
Definition at line 246 of file sqlite3x_command.cpp.
void sqlite3x::sqlite3_command::prepare | ( | char const * | sql, |
int | len = -1 ) |
Prepares this statement or throws on error.
If len is -1 then sql is assumed to be null-terminated.
Definition at line 66 of file sqlite3x_command.cpp.
References sqlite3x::sqlite3_connection::db(), and finalize().
Referenced by prepare(), sqlite3_command(), and sqlite3_command().
void sqlite3x::sqlite3_command::prepare | ( | std::string const & | sql | ) |
Convenience overload taking a std::string.
Definition at line 85 of file sqlite3x_command.cpp.
References prepare().
bool sqlite3x::sqlite3_command::reset | ( | ) |
Resets this statement using sqlite3_reset().
Errors are considered to be minor and only cause false to be returned.
Definition at line 236 of file sqlite3x_command.cpp.
Referenced by sqlite3x::sqlite3_cursor::reset().
|
friend |
Definition at line 597 of file sqlite3x.hpp.