28 #include "sqlite3x.hpp"
36 return ((SQLITE_DONE==rc) || (SQLITE_OK==rc) || (SQLITE_ROW==rc));
42 : m_db(NULL), m_name(dbn)
47 #if SQLITE3X_USE_WCHAR
56 throw database_error(
"sqlite3_connection(sqlite3*) ctor was passed a null db handle." );
77 if( this->m_db == dbh )
return;
80 if( this->m_db || (!dbh) )
99 sqlite3 * ret = this->m_db;
116 char const * m = this->m_db ? sqlite3_errmsg(this->m_db) :
"";
126 this->m_name = db ? db :
"";
127 if(sqlite3_open(db, &this->m_db)!=SQLITE_OK)
128 throw database_error(
"unable to open database %s", db ? db :
"<null>");
141 try { this->
close(); }
149 return this->
open( db.c_str() );
152 #if SQLITE3X_USE_WCHAR
154 if(sqlite3_open16(db, &this->m_db)!=SQLITE_OK)
162 try { this->
close(); }
171 sqlite3 * x = this->m_db;
173 if(sqlite3_close(x)!=SQLITE_OK)
180 return sqlite3_last_insert_rowid(this->m_db);
185 return sqlite3_changes(this->m_db);
192 if(sqlite3_busy_timeout(this->m_db, ms)!=SQLITE_OK)
205 #if SQLITE3X_USE_WCHAR
220 #if SQLITE3X_USE_WCHAR
236 #if SQLITE3X_USE_WCHAR
252 #if SQLITE3X_USE_WCHAR
264 #if SQLITE3X_USE_WCHAR
271 #if SQLITE3X_USE_WCHAR
272 std::wstring sqlite3_connection::executestring16(
const std::string &sql) {
273 if(!this->m_db)
throw database_error(
"database is not open");
274 return sqlite3_command(*
this, sql).executestring16();
278 #if SQLITE3X_USE_WCHAR
279 std::wstring sqlite3_connection::executestring16(
const std::wstring &sql) {
280 if(!this->m_db)
throw database_error(
"database is not open");
281 return sqlite3_command(*
this, sql).executestring16();
290 #if SQLITE3X_USE_WCHAR
298 sqlite3_callback callback,
300 std::string & errmsg )
307 ret = sqlite3_exec( this->m_db, sql.c_str(), callback, data, &cerrmsg );
314 sqlite3_free( cerrmsg );
321 sqlite3_free( cerrmsg );
327 sqlite3_callback func,
343 std::vector<std::string> list;
375 int check = con.
executeint(
"select count(*) from sqlite_master where type like 'table' and name like '"+n+
"'" );
379 throw database_error(
"table_generator() db table '%s' already exists.", n.c_str() );
381 this->m_pimpl->db = &con;
382 this->m_pimpl->name = n;
387 delete this->m_pimpl;
392 this->m_pimpl->list.push_back( fld );
398 size_t sz = this->m_pimpl->list.size();
401 throw database_error(
"table_generator::operator(): cannot create a table with no fields. Try using operator()(string) to add fields." );
403 std::ostringstream os;
404 os <<
"create table "<< this->m_pimpl->name <<
"(";
405 for(
size_t i = 0; i < sz; ++i )
407 os << this->m_pimpl->list[i];
408 if( i < (sz-1) ) os <<
",";