Ketai library SQLite - can't insert into DB

edited January 2018 in Android Mode

I am following the example at Ketai to insert a new row into an existing SQLite database. I am using a simple SQL insert statement. The println statements at the bottom from a SELECT statement suggests that everything works - I can see new rows being added to the DB. However when I go into the database itself the rows are NOT being written. Is there something obvious I am missing?

I am running this via an Android Emulator from the Processing IDE. I am beginning to suspect something to do with the emulator (or some permission thing?) as the code seems fine .... ?

import ketai.data.*;

class DB {
  KetaiSQLite db;
  DB(PApplet p) {
    if (KetaiSQLite.load(p, "diaryDB.db", "diaryDB")) {
      println("loaded db file");
    }
    db = new KetaiSQLite(p,"diaryDB");
  }

  void write(String s) {
    if (db.connect()) {
      String query = "INSERT INTO DIARY VALUES(NULL,\""+s+"\",1)";    
      if (!db.execute(query)) {
        println("error w/sql insert");
      }
      println("data count for data table after insert: "+db.getRecordCount("DIARY"));
      db.query( "SELECT * FROM DIARY" );

      while (db.next ())
      {
        println("----------------");
        print( db.getInt("DIARY_ID") );
        print( "\t"+db.getString("TEXT_ENTRY") );
        println("\t"+db.getInt("MOOD_ID"));   
        println("----------------");
      }
    } else {
      println("db not connected");
    }
  }
}

Answers

  • Answer ✓

    Never mind, I created a db within the code and its now working.

Sign In or Register to comment.