Conflict of versions of the Sqlite database



  • Hello, I'm building a database that's filled with cloud storage.

    The database class is reading and recording sqlite data. I'm checking the Internet connection and doing the autopsy.

    /options.getVersion - version of the cloud database

     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);
    

    Then I have to make a request in some piece. 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, I don't know what I'm saying in the design, options.

    Mistake: Can't downgrade database from version 25 to 1

    Or maybe I don't even know how to read the base in a fragment.



  • On reading from the fragment, according to your code, you must address your local base. The version of the OBD in this case is determined by you. So it has nothing to do with the OBD version. So, when your local BDE is opened, use the designer:

    mDatabaseHelper = new DatabaseHelper(this);
    

    If the data change to the OBD, the version should not change. The version of the OBD should be changed when its structure is changed, and since your OBD depends on cloud-based OBD, you will change your OBD when the OBD changes in the cloud. At the same time, you'll have to redesign the Upgrade method to your class.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2