SQLite的"数据库模式已经改变"错误内容提供商 [英] SQLite "database schema has changed" error in Content Provider
问题描述
我用内容提供商
和同步适配器
我的同步例程。
我的日常收到的JSONObject
键,插入或更新条目。
为了决定是否我们要更新或插入,我们检查,如果在数据库中存在的条目。这是SQLite的错误发生。
10月六日至3日:58:21.239:信息/数据库(340):sqlite的返回:错误code = 17,味精= prepared声明中止在45: [SELECT * FROM表WHERE(ID =?)ORDER BY ID]
我已经做了一些研究,发现这个讨论的主题。从这个讨论中,我了解到, sqlite_exec()
已被调用。我将如何在内容提供商实现这一点?
修改
插入/更新检查
//更新或插入
ContentValues CV =新ContentValues();
/ *把信息从JSON到CV * /
如果(mContentResolver.update(ClientsProvider.CONTENT_URI,CV,NULL,NULL)== 0){
//添加条目的远程ID
cv.put(RID,o.optInt(ID));
mContentResolver.insert(ClientsProvider.CONTENT_URI,CV);
}
的ContentProvider ::更新
@覆盖
公众诠释更新(开放的URI,ContentValues价值观,选择字符串,字符串[] selectionArgs两个){
诠释计数= 0;
开关(uriMatcher.match(URI)){
案例客户:
数= clientDB.update(TABLE_NAME,价值观,选择,selectionArgs两个);
打破;
案例CLIENT_ID:
数= clientDB.update(TABLE_NAME,价值观,ID +=+ uri.getPathSegments()得到(0)+(TextUtils.isEmpty(选择)AND(+选择+')'。!?) ,selectionArgs两个);
打破;
默认:
计数= 0;
}
返回计数;
}
问题就解决了。我不知道为什么,但模拟器图像擦拭后一切正常,它应该到底怎么做。感谢您的时间Selvin!
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;
}
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!
这篇关于SQLite的"数据库模式已经改变"错误内容提供商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!