不正确的RowId使用SQLite使用FTS3在Android 2.2 [英] Incorrect RowId with SQLite using FTS3 on Android 2.2

查看:335
本文介绍了不正确的RowId使用SQLite使用FTS3在Android 2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了不正确的ROWID值的SQLite和FTS3。

I am experiencing an incorrect rowid value with sqlite and fts3.

基本上,前两行被插入和其rowid为1和2的 分别。然而,第三插入件返回4代替3-

Basically, the first two rows are inserted and the rowId is 1 and 2 respectively. The third insert however returns 4 instead of 3.

我在我的ContentProvider时回落以下日志消息 插入行:

I dropped the following log message in my contentprovider when inserting a row:

SQLiteDatabase database =
databaseHelper.getWritableDatabase();
long rowId = database.insert(NOTES_TABLE, Note.NOTE, values);
Log.d("NoteProvider", "RowId inserted was " + rowId);

这是日志信息的输出是:

The output of that log message is:

02-21 21:10:12.773: DEBUG/NoteProvider(2486): RowId inserted was 1
02-21 21:10:20.623: DEBUG/NoteProvider(2486): RowId inserted was 2
02-21 21:10:25.883: DEBUG/NoteProvider(2486): RowId inserted was 4

到底发生了什么,以3?

So what happened to 3?

另外,我出口的SQLite数据库,所以我可以看看一个SQLite 浏览器和内容表显示1,2和3。

Also, I exported the sqlite database so I could look at in a SqLite browser and the content table shows 1, 2 and 3.

所以3被创造,但4被退回。

So 3 was created but 4 was returned.

我跑我的测试中高达10个,而ROWID是顺序之后, 但仍然关闭的1。

I ran my testing up to 10, and the rowId was sequential afterwards, but still off by 1.

该数据库创建脚本是:

database.execSQL("CREATE VIRTUAL TABLE " + NOTES_TABLE + "
USING fts3 ("
           + Note.TITLE + ", "
           + Note.NOTE + ", "
           + Note.CREATED_DATE + ", "
           + Note.MODIFIED_DATE + ");");

我假设我已经做了一些可怕的错误,但不能图 它是什么。 谁能帮助我?

I am assuming I have done something horribly wrong, but cannot figure out what it is. Can anyone help me out?

修改1:
做了一些更多的测试,并且对2.3.1和2.1相同的结果。
虽然2.1的IDS 1时,3(跳过2)

Edit 1:
Did some more testing and have the same results on 2.3.1 and 2.1.
Although in 2.1 the ids when 1, 3 (skipped 2)

编辑2:
终于想出了一个变通。不过,我认为这是一个pretty的严重错误或什么的。 我落得这样做是请从表中颠簸了1个,然后设置这个值在插入的ROWID最大的rowid。它是一个完整的吸液。一个非常肮脏的和便宜的黑客,但它是我得到可靠地工作的唯一的事。反正这里是code:

Edit 2:
Finally came up with a work around. However I think this is a pretty severe bug or something. What I ended up doing was selecting the max rowid from the table bumping up by 1 and then setting that value to the rowid on insert. Its a complete suck solution. A very dirty and cheap hack, but it is the only thing I get to work reliably. Anyway here is the code:

SQLiteDatabase database = databaseHelper.getWritableDatabase();
SQLiteStatement statement = database.compileStatement("select ifnull(max(rowid), 0) as rowid from " + NOTES_TABLE);
long maxRowId = statement.simpleQueryForLong();
Log.d("NoteProvider", "Statement returned " + maxRowId);
long rowId = maxRowId + 1;
values.put("rowid", rowId);
database.insert(NOTES_TABLE, null, values);
Log.d("NoteProvider", "RowId inserted was " + rowId);

修改3:
看起来像另一个人是/是有这个问题。 Android的全文搜索和ListAdapter

Edit 3:
Looks like another fellow was/is having this problem. Android Full Text Search and ListAdapter

推荐答案

这看起来是SQLite中的一个错误。在原来的职位编辑2的解决方案似乎是工作确定。还没有尝试过在蜂窝来验证它已被固定在那里。

This looks to be a bug in SQLite. The solution in "Edit 2" of the original post seems to be working ok. Have not tried it out in Honeycomb to verify it has been fixed there.

这篇关于不正确的RowId使用SQLite使用FTS3在Android 2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆