24 #include "sqlite3x.hpp" 30 : con(con),stmt(0),refs(0),argc(0)
36 : con(con),stmt(0),refs(0),argc(0)
42 : con(con),stmt(0),refs(0),argc(0)
44 this->
prepare( sql, static_cast<int>( len ) );
47 #if SQLITE3X_USE_WCHAR 48 sqlite3_command::sqlite3_command(
sqlite3_connection &con,
const std::wstring &sql) : con(con),stmt(0),refs(0),argc(0) {
49 const void *tail=NULL;
51 #if (SQLITE_VERSION_NUMBER >= 3003009) 56 (con.
db(), sql.data(), (int)sql.length()*2, &this->stmt, &tail);
59 throw database_error(
"sqlite3_command::prepare failed. Reason=[%s]",
60 sqlite3_errmsg( this->con.
db() ) );
62 this->argc=sqlite3_column_count(this->stmt);
69 const char *tail=NULL;
71 #if (SQLITE_VERSION_NUMBER >= 3003009) 76 ( this->con.
db(), sql, len, &(this->stmt), &tail );
79 throw database_error(
"sqlite3_command::prepare([%s]) failed. Reason=[%s]",
80 sql, sqlite3_errmsg( this->con.
db() ) );
82 this->argc=sqlite3_column_count(this->stmt);
87 this->
prepare( sql.c_str(),
static_cast<int>( sql.size()) );
107 if(sqlite3_finalize(this->stmt)!=SQLITE_OK)
114 if(sqlite3_bind_null(this->stmt, index)!=SQLITE_OK)
119 if(sqlite3_bind_int(this->stmt, index, data)!=SQLITE_OK)
124 if(sqlite3_bind_int64(this->stmt, index, data)!=SQLITE_OK)
129 if(sqlite3_bind_double(this->stmt, index, data)!=SQLITE_OK)
134 if(sqlite3_bind_text(this->stmt, index, data,
140 SQLITE_TRANSIENT)!=SQLITE_OK)
144 #if SQLITE3X_USE_WCHAR 146 if(sqlite3_bind_text16(this->stmt, index, data, datalen, SQLITE_TRANSIENT)!=SQLITE_OK)
152 if(sqlite3_bind_blob(this->stmt, index, data, datalen, SQLITE_TRANSIENT)!=SQLITE_OK)
157 if(sqlite3_bind_text(this->stmt, index, data.data(), (int)data.length(), SQLITE_TRANSIENT)!=SQLITE_OK)
161 #if SQLITE3X_USE_WCHAR 163 if(sqlite3_bind_text16(this->stmt, index, data.data(), (int)data.length()*2, SQLITE_TRANSIENT)!=SQLITE_OK)
206 #if SQLITE3X_USE_WCHAR 207 std::wstring sqlite3_command::executestring16() {
210 return reader.getstring16(0);
223 return reader.
getblob(0, size);
230 throw database_error(
"sqlite3_command::colcount(): statement has not been prepared");
232 return sqlite3_column_count( this->stmt );
241 rc = sqlite3_reset( this->stmt );
243 return rc == SQLITE_OK;
sqlite3_cursor executecursor()
Executes the query and returns a cursor object which can be used to iterate over the results...
std::string getstring(int index)
Gets the string value at the given field number.
void executenonquery()
Executes the query and provides no way to get the results.
A type for reading results from an sqlite3_command.
This namespace encapsulates a C++ API wrapper for sqlite3 databases.
Represents a connection to an sqlite3 database.
std::string executeblob()
Executes the query, which is expected to have a string or blob field as the first result field...
std::string getblob(int index)
Gets the blob value at the given field number.
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 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...
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.
void bind(int index)
Binds NULL to the given index.
void finalize()
Finalizes this statement.
sqlite3_stmt * handle()
Returns the underlying statement handle.
int64_t getint64(int index)
Gets the (int64_t) value at the given field number.
bool step()
Steps one step through the sql result set and returns true on SQLITE_ROW, false on SQLITE3_DONE...
~sqlite3_command()
Cleans up any resources in use by this object.
Exception type used by the sqlite3x classes.
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.
int executeint()
Executes the query, which is expected to have an integer field as the first result field...