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;