Hello, I create a database, the data of which I fill in from cloud storage.
The Database class reads and writes data to the sqlite. I check my internet connection and upgrade.
//options.getVersion - version of the database in the cloud
mDatabaseHelper = new DatabaseHelper(context,"mydatabase.db",null, options.getVersion()); mSqLiteDatabase = mDatabaseHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(mDatabaseHelper.OPTIONS_COLUMN_MAP, options.getMap()); values.put(mDatabaseHelper.OPTIONS_COLUMN_VERSION, options.getVersion()); mSqLiteDatabase.insert(mDatabaseHelper.TABLE_OPTIONS, null, values); Next, I need to make a request in some fragment. For example:
mDatabaseHelper = new DatabaseHelper(context,"mydatabase.db",null, ??????); // здесь проблема mSqLiteDatabase = mDatabaseHelper.getWritableDatabase(); TextView textView = (TextView) getView().findViewById(R.id.textView4); Cursor c = mSqLiteDatabase.rawQuery("SELECT * FROM options", null); if (c.moveToFirst()) { textView.setText(c.getString(c.getColumnIndex(mDatabaseHelper.COLUMN_ABOUT))); } The problem is that I don’t know what version to indicate to me in the constructor. options.version will be zero when the cloud is unavailable.
Error: Can't downgrade database from version 25 to 1
Or maybe I’ll even incorrectly organize the reading of the base in the fragment