Upgrading from java-based android app to react native and SQLite storage

150 Views Asked by At

I believe there is only one location databases can be stored on Android but also wondering if the file extension for SQLiteOpenHelper is .db3, .db, or user defined and if not defined there is no extension.

Any help?

My scenario is: I have a java based android app in the play store currently and it opens the database like so (relevant code only):

private static final String DATABASE_NAME = "data";

    private static class DatabaseHelper extends SQLiteOpenHelper {

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

        @Override
        public void onCreate(SQLiteDatabase db) {

            db.execSQL(DATABASE_CREATE);
        }


        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // do stuff
        }

        public boolean checkIfColumnExist(SQLiteDatabase db, String column) {

            Cursor cursor = db.rawQuery("SELECT * FROM " + DATABASE_TABLE + " limit 1", null);

            if(cursor == null) return false;

            cursor.moveToFirst();

            boolean exist = cursor.getColumnIndex(column) != -1;
            cursor.close();

            return exist;
        }
    }

// in constructor of another db wrapper
mDbHelper = new DatabaseHelper(mCtx);


// open function of db wrapper
public void open() throws SQLException {
  mDb = mDbHelper.getWritableDatabase();
}

That works fine (older app) and has been for a while.

What I'm doing in react native is using react-native-sqlite-storage like so:


import SQLite from 'react-native-sqlite-storage';
SQLite.enablePromise(true);

const Database = {
  DATABASE_NAME: 'data'
};

this.db = await SQLite.openDatabase({ name: Database.DATABASE_NAME, location: 'default' });

The above works on a clean install but when I test upgrading from the older java-based android version to a newer version react native version it doesn't.

One thing to note is that I'm testing this upgrade in a janky way. I'm a "internal tester" for the app and I installed the java-based one via play store and then added myself to the internal tester group, then "updated" it to the react native one. I don't think this would be an issue but it's been a while since I've done internal testing and not sure of all the quirks.

0

There are 0 best solutions below