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. More... | |
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. More... | |
~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. More... | |
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. More... | |
void | bind (int index, const void *data, int datalen) |
Binds data to the given query index. More... | |
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. More... | |
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. More... | |
char const * | executestring (int &size) |
Like executestring(), but returns a C-style string. More... | |
std::string | executeblob () |
Executes the query, which is expected to have a string or blob field as the first result field. More... | |
void const * | executeblob (int &size) |
Like executeblob(), but returns a void pointer to the data. More... | |
int | colcount () |
Returns the column count of this object's query, or throws on error. | |
bool | reset () |
Resets this statement using sqlite3_reset(). More... | |
sqlite3_stmt * | handle () |
Returns the underlying statement handle. More... | |
void | finalize () |
Finalizes this statement. More... | |
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, |
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().
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 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.
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().
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(), 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(), and sqlite3_command().
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().