I am trying to create a simple android application which creates a database using SQLiteDatabase (not using SQLiteOpenHelper). So the database creation and the table creation sql executes successfully without any issues/exceptions.
Now the issue is when I reopen the same database, the earlier table created does not exist!!
I am checking the existence of the table using the following code :
Cursor cursor = db.rawQuery("select DISTINCT tbl_name from sqlite_master where tbl_name = '"+ sqlQueryString +"'", null);
if(cursor!=null) {
if(cursor.getCount() == 0) {
//error handling code here
}
cursor.close();
}
Obviously am ending in the if(cursor.getCount() == 0) condition.
I pulled the db file and also checked with a sqlite viewer on the pc, the table created earlier simply does not exist.
So my question is how do I verify that my create table query has created the table properly?
Adding requested information:
Create table ExampleTable ( ROWID integer primary key autoincrement , FIRSTNAME text , LASTNAME text ) ;
Adding the android code the execute the above query:
db.beginTransaction();
db.execSQL(sqlQueryString);
db.endTransaction();
You need to call
db.setTransactionSuccessful()before you end the transaction, or else the operation is assumed to have failed and the transaction is rolled back.Typical transaction usage is:
Credit to njzk2 for first mentioning the solution in a comment.