After deleting android database, getReadableDatabase () will not create new database

I deleted the android database by running the command rm / data / data / app / databases / database. After I removed it I tried to run the application again and this is an exception because no tables were created. Exception I get E / AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to create service wificontroller.WifiControllerService: android.database.sqlite.SQLiteException: No table like this:

I am creating 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 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 nor On Upgrade gets called. I wish I could post the queries they will impregnate, but I know they compile correctly because this has been working for a long time.

I tried reinstalling the app and deleting all user data and nothing worked. Any thoughts on why I suddenly can't query my database.

+3


source to share


2 answers


You must update the version.

try



private static final int Version = 3;

      

+1


source


Just in case, other people also face this problem. The mine initially failed because the database didn't know that the database had changed and I needed to increase the version as above, but I had a very similar problem where my creation attempt failed before it tried everything requests. One of the requests was bad and the first time I did it it failed, but every time after that it didn't try to call Create again. In short, if Oncreate fails once, you must completely uninstall the app from your phone and try again.



+3


source







All Articles