私は同期ルーチンにContent Providers
andを使用しています。Sync Adapters
私のルーチンは を受け取りJSONObject
、エントリを挿入または更新します。
更新するか挿入するかを決定するために、エントリがデータベースに存在するかどうかを確認します。ここで sqlite エラーが発生します。
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]
私はいくつかの調査を行い、主題に関するこの議論を見つけました。この議論から、私はそれsqlite_exec()
が呼び出されなければならないことを理解しています。これをコンテンツ プロバイダに実装するにはどうすればよいですか?
編集
挿入・更新チェック
// 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::アップデート
@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;
}