I deleted the android database by executing rm /data/data/app/databases/database. After I removed it I tried running the app again and it thows an exception because the tables have not been created. The exception I get is E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to create service wificontroller.WifiControllerService: android.database.sqlite.SQLiteException: no such table:
I create the tables in
public class DataStore extends SQLiteOpenHelper{
private static final String TAG = "Database";
private static final String DatabaseName = "Database";
private static final String NICKNAME_TABLE_NAME = "nicknames";
private static final String SCAN_TABLE_NAME = "scans";
private static final int Version = 2;
private static final String NICKNAME_TABLE_CREATE = "Query I cant show"
private static final String SCAN_TABLE_CREATE = "Query I cant show"
public DataStore(Context context) {
super(context, DatabaseName , null, Version);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG, "Creating database");
try {
db.execSQL(NICKNAME_TABLE_CREATE);
db.execSQL(SCAN_TABLE_CREATE);
}
catch (Exception e){
Log.e(TAG, "Could not create database", e);
Log.e(TAG, "Query 1: " + NICKNAME_TABLE_CREATE);
Log.e(TAG, "Query 2: " + SCAN_TABLE_CREATE);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "On Upgrade called");
}
public String[] getScanColumns(){
return new String[]{"accessPoints", "clients", "status","timeOfStartScan", "packetsFound"};
}
public String getDatabaseName(){
return DatabaseName;
}
public String getScanTableName(){
return SCAN_TABLE_NAME;
}
and the Method that is calling the database is
SQLiteDatabase database = dbHelper.getReadableDatabase();
Cursor mCursor = database.rawQuery("SELECT QUERY", null); //THIS IS THE LINE THAT THROWS THE EXCEPTION
try {
if (mCursor != null) {
mCursor.moveToFirst();
Log.w(Tag, "Packets found on last scan = " + mCursor.getString(mCursor.getColumnIndex("packetsFound")));
Log.i(Tag, "Successfully loaded database scan");
} else {
Log.w(Tag, "Could not retrieve scan from database");
}
}
catch (Exception e){
Log.w(Tag, "Could not retrieve scan data from database probably because it doesn't exist");
}
finally {
mCursor.close();
}
I have verified that neither On Create or On Upgrade are getting called. I am sorry I cant post the queries they are propietry however I know they compile correctly because this has been working for a long time.
I have tried reinstalling the app and deleting all user data and nothing has worked. Any thoughts on why I would all of a sudden I can't query my database anymore.
Aucun commentaire:
Enregistrer un commentaire