mardi 23 février 2016

How do I create tables dynamically in SQLite in Android?

I am creating an application where a table gets generated in SQLite Database as soon as a new user registers, but I can create tables only in the onCreate() method in the SQLiteOpenHelper class. I am using this user-defined function to create tables dynamically :

 public void createUserTable(DatabaseOperations d,String user){
    String USER_Q="CREATE TABLE "+user+"("+UserInfo.NOTES+" text);";
    SQLiteDatabase dp=d.getWritableDatabase();
    dp.execSQL(USER_Q);
}

but it does not work as I get the error while retreiving the notes column from the user table:

 Caused by: android.database.sqlite.SQLiteException: no such table: Bundle (code 1): , while compiling: SELECT notes FROM Bundle[mParcelledData.dataSize=72]

How can I create new tables with or without using the onCreate() method?

Aucun commentaire:

Enregistrer un commentaire