SQLite "database schema changed" error in Content Provider

I use Content Providers and Sync Adapters for my synchronization process.

My procedure receives a JSONObject and inserts or updates the record.

To decide whether we will update or insert, we check to see if a record exists in the database. This is where sqlite error occurs.

 06-03 10:58:21.239: INFO/Database(340): sqlite returned: error code = 17, msg = prepared statement aborts at 45: [SELECT * FROM table WHERE (id = ?) ORDER BY id] 

I did some research and found this discussion on this subject. From this discussion, I understand that sqlite_exec() should be called. How to implement this in the content provider?

Edit

Insert / Update Validation

 // Update or Insert ContentValues cv = new ContentValues(); /* put info from json into cv */ if(mContentResolver.update(ClientsProvider.CONTENT_URI, cv, null, null) == 0) { // add remote id of entry cv.put("rid", o.optInt("id")); mContentResolver.insert(ClientsProvider.CONTENT_URI, cv); } 

ContentProvider :: Update

 @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { int count = 0; switch(uriMatcher.match(uri)) { case CLIENTS: count = clientDB.update(TABLE_NAME, values, selection, selectionArgs); break; case CLIENT_ID: count = clientDB.update(TABLE_NAME, values, ID + " = " + uri.getPathSegments().get(0) + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs); break; default: count = 0; } return count; } 
+1
source share
1 answer

The problem is resolved. I'm not sure why, but after the emulator image is wiped, everything works exactly as it should. Thanks for your time, Selvin!

+1
source

Source: https://habr.com/ru/post/1394153/


All Articles