SQLite “database schema has changed” error in Content Provider

纵然是瞬间 提交于 2019-12-11 08:42:10

问题


I'm using Content Providers and Sync Adapters for my synchronization routine.

My routine receives a JSONObject and insert or update the entry.

In order to decide if we are going to update or insert we check if the entry exists in the database. This is where the 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 have done some research and found this discussion about the subject. From this discussion I understand that sqlite_exec() has to be called. How would I implement this in a Content Provider?

Edit

Insert / Update check

// 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:


Problem is solved. I'm not sure why but after an emulator image wipe everything works exactly how its supposed to do. Thank you for your time Selvin!



来源:https://stackoverflow.com/questions/6226299/sqlite-database-schema-has-changed-error-in-content-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!