【发布时间】:2015-10-19 18:39:49
【问题描述】:
我正在使用 Android Sync Adapter 框架将本地数据库与远程数据库同步。在 onPerformSync 中,我有一个 (ContentProviderClient provider) 实例,它使用本地数据库完成所有工作。要访问正确的数据库,我必须提供内容 Uri(在我的情况下是 ServiceContract.CHECKINS_DATA_URI - content://authority/checkins)它在查询操作中工作正常但是当我尝试更新时DB 我得到错误:
android.database.sqlite.SQLiteException: near "SET": syntax error (code 1): , while compiling: UPDATE SET status=?,timestamp=?,user_id=?,checking_id=? WHERE timestamp = ?
在 UPDATE 和 SET 运算符之间缺少表名。这有点神秘,因为我使用了正确的 Uri。您认为什么会导致此错误?
公共类 SyncAdapter 扩展 AbstractThreadedSyncAdapter {
ContentResolver mContentResolver;
SvcController mController;
public SyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);
mContentResolver = context.getContentResolver();
mController = new SvcController(context.getApplicationContext());
}
public SyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) {
super(context, autoInitialize, allowParallelSyncs);
mContentResolver = context.getContentResolver();
}
@Override
public void onPerformSync(Account account,
Bundle extras,
String authority,
ContentProviderClient provider,
SyncResult syncResult) {
ContentValues cv;
String[] projection;
String selection;
String[] selectionArgs;
Uri uri;
...
// updates checkin_id in local db
uri = ServiceContract.CHECKINS_DATA_URI;
selection = "timestamp = ?";
for (CheckIn ci : checkins){
cv = ci.toContentValues();
selectionArgs = new String[]{String.valueOf(ci.getTimestamp().getTime())};
try {
provider.update(uri, cv, selection, selectionArgs);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
}
【问题讨论】:
标签: android android-contentprovider android-syncadapter