Android : android.database.sqlite.SQLiteException: no such table: FTStable1 (code 1): , while compiling: SELECT idtable FROM FTStable1 ORDER BY name

on Sunday, September 21, 2014


I want to create a SQLite DB, and i get the error SQLiteException: no such table when i do the first SELECT. My app at first do a Select to know if the Table is empty and then call a WS online to get data to Insert.


Thanks for help.


The SELECT:



static private ItemsDbAdapter dbHelper;
....
dbHelper = new ItemsDbAdapter(getActivity());
dbHelper.open();
cursor = dbHelper.fetchAllItems("name");


The ItemsDbAdapter Class:



private static class DatabaseHelper extends SQLiteOpenHelper {
private static final String FTS_TABLE_CREATE =
"create table " + FTS_VIRTUAL_TABLE + "(" + KEY_ID + " integer primary key not null, " +
KEY_NAME + " text not null);";


DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {

db.execSQL(FTS_TABLE_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS FTStable1");
onCreate(db);
}
}

public ItemsDbAdapter(Context context) {
mDbHelper = new DatabaseHelper(context);
this.mCtx = context;
}

public ItemsDbAdapter open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);

mDb = mDbHelper.getWritableDatabase();
//mDbHelper.onUpgrade(mDb,1,2); --> this is when i want to Upgrade version
return this;
}

public void close() {
mDbHelper.close();
}

0 comments:

Post a Comment