namespace jme {
 class Runner : public Gtk::Window {
 private:
 jme::Exception* e; // Exception handler
 sqlite3 *db; // Data Base
 sqlite3_stmt* stmt; // SQL statement
 Glib::ustring dbName; // db name
 Glib::ustring sName; // my name
 Glib::ustring sAddress; // my address
 Glib::ustring vfs; // MSWIN Identifier
 int rc; // return code
 int age; // my age
 // SQL statement
 Glib::ustring dbdata;
 Glib::ustring create_table;
 public:
 Runner();
 ~Runner();
 void OpenDB();
 void CreateTable();
 void AddData();
 };
 }
 void jme::Runner::CreateTable(){
 rc = sqlite3_prepare_v2(
 db, /* Database handle */
 create_table.c_str() , /* SQL statement, UTF-8 encoded */
 create_table.length(), /* Maximum length of zSql in bytes. */
 &stmt, /* OUT: Statement handle */
 NULL /* OUT: Pointer to unused portion of zSql */
 );
 if(rc != SQLITE_OK) {
 sqlite3_close(db);
 std::cout << "error prepare_v2: " << rc << std::endl;
 exit(-2);
 }
 rc = sqlite3_step(stmt);
 if(rc != SQLITE_DONE) {
 sqlite3_close(db);
 std::cout << "error sqlite3_step: " << rc << std::endl;
 exit(-3);
 }
 sqlite3_finalize(stmt);
 }
 void jme::Runner::AddData(){
 rc = sqlite3_prepare_v2(
 db, /* Database handle */
 dbdata.c_str() , /* SQL statement, UTF-8 encoded */
 dbdata.length(), /* Maximum length of zSql in bytes. */
 &stmt, /* OUT: Statement handle */
 NULL /* OUT: Pointer to unused portion of zSql */
 );
 if(rc != SQLITE_OK) {
 ....
 }
 rc = sqlite3_step(stmt);
 if(rc != SQLITE_DONE) {
 ....
 }
 sqlite3_finalize(stmt);
 }
 void jme::Runner::OpenDB() {
 rc = sqlite3_open_v2(dbName.c_str(),
 &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
 NULL);
 if(rc != SQLITE_OK) {
 ....
 }
 jme::Runner::Runner() {
 dbName = "sqliteTest.sql";
 sName = "ArbolOne";
 sAddress = "1 Parkway Rd";
 vfs = "win32";
 age = 22;
 dbdata = "INSERT INTO friend VALUES('Jamiil', '49 New Bridge', '49')";
 create_table = "CREATE TABLE friend (name TEXT, address TEXT, age INT)";
 try {
 jme::gnu_io f;
 f.deleteFile(dbName);
 } catch(jme::Exception e) {
 std::cout << e.what() << std::endl;
 }
 OpenDB();
 CreateTable();
 AddData();

 }
 jme::Runner::~Runner(){
 sqlite3_close(db);
 cout << "Good bye!" << endl;
 }
 int main(int argc, char *argv[]) {
 try {
 Gtk::Main kit(argc, argv);
 jme::Runner dbtest;
 Gtk::Main::run(dbtest);
 } catch(jme::Exception& x) {
 x.Display();
 }
 return 0;
 }
 This is what I have done so far, and following your advice I hade added 
'sqlite3_finalize(stmt)' each time I am done with it. Also, I have downloaded 
and installed 'SQLight Designer' and when opening the database file, I have 
just created, all that I can see is the words: SQLite format 3.
 Come on you folk, you have more experience than me using SQLite, pich in!. 
What else do I need to do?

 TIA

 void jme::Runner::CreateTable(){
 rc = sqlite3_prepare_v2(
 db, /* Database handle */
 create_table.c_str() , /* SQL statement, UTF-8 encoded */
 create_table.length(), /* Maximum length of zSql in bytes. */
 &stmt, /* OUT: Statement handle */
 NULL /* OUT: Pointer to unused portion of zSql */
 );
 if(rc != SQLITE_OK) {
 sqlite3_close(db);
 std::cout << "error prepare_v2: " << rc << std::endl;
 exit(-2);
 }
 rc = sqlite3_step(stmt);
 if(rc != SQLITE_DONE) {
 sqlite3_close(db);
 std::cout << "error sqlite3_step: " << rc << std::endl;
 exit(-3);
 }
 sqlite3_finalize(stmt);
 }
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to