1 // OVSQLite3.h 2 3 #ifndef __OVSQLite3_h 4 #define __OVSQLite3_h 5 6 #include <sqlite3.h> 7 8 class SQLite3Statement { 9 public: SQLite3Statement(sqlite3_stmt * st)10 SQLite3Statement(sqlite3_stmt *st) : s(st) {} ~SQLite3Statement()11 ~SQLite3Statement() { sqlite3_finalize(s); } reset()12 int reset() { return sqlite3_reset(s); } bind_text(int c,const char * t)13 int bind_text(int c, const char *t) 14 { 15 return sqlite3_bind_text(s, c, t, -1, SQLITE_TRANSIENT); 16 } bind_int(int c,int i)17 int bind_int(int c, int i) { return sqlite3_bind_int(s, c, i); } 18 step()19 int step() { return sqlite3_step(s); } column_text(int c)20 const char *column_text(int c) 21 { return (const char*)sqlite3_column_text(s, c); } column_int(int c)22 int column_int(int c) { return sqlite3_column_int(s, c); } column_count()23 int column_count() { return sqlite3_column_count(s); } 24 protected: 25 sqlite3_stmt *s; 26 }; 27 28 class SQLite3 { 29 public: open(const char * f)30 int open(const char *f) { return sqlite3_open(f, &handle); } close()31 int close() { return sqlite3_close(handle); } errcode()32 int errcode() { return sqlite3_errcode(handle); } prepare(const char * sqlcmd)33 SQLite3Statement *prepare(const char *sqlcmd) 34 { 35 sqlite3_stmt *s; 36 const char *rms; 37 if (sqlite3_prepare(handle, sqlcmd, -1, &s, &rms)) return NULL; 38 return new SQLite3Statement(s); 39 } 40 protected: 41 sqlite3 *handle; 42 }; 43 44 #endif 45