SQLiteDatabase光标空只能在Android 5.0+设备 [英] SQLiteDatabase Cursor empty only on Android 5.0+ devices
问题描述
应用程序有一个搜索查看
这从一个特定的数据库表获取建议。一切工作没有任何错误,直到的是Android 5.0出现了。
由于然后,当 SQLiteQueryBuilder
查询数据库,填补了光标
对象,则返回空光标。没有 NULL
,但空。
在其他平台上,我可以输出光标
的通过 DatabaseUtils.dumpCursorToString(cursorObject)含量
,但在Android 5.0以上版本的方法对空的对象报告输出
倾销光标空结果
<<<<<
块引用>更:当我提取5.0+设备数据库文件,然后运行本地SQL查询,我可以获取所有数据。因此,数据库是确实有效。而查询是最简单的一种
SELECT ROWID AS _id,suggest_text_1,suggest_text_2,ROWID AS suggest_intent_data_id
从FTS
WHERE(FTS MATCH'* E *)//< - 我pressedE在键盘上从数据库中选择数据并填充
光标
对象的逻辑是非常简单的。SQLiteQueryBuilder建设者=新SQLiteQueryBuilder();
builder.setTables(FTS3_TABLE);
builder.setProjectionMap(mColumnMap); 光标光标= builder.query(DB,列,选择,selectionArgs两个,
NULL,NULL,NULL);我试图寻找一些德precated方法,但没有任何运气。
我已经了3天调试的过程中的每一步,我出任何想法可能会导致这样的行为。
任何人有什么想法?
修改
该方法的输出
BuildQuery对于()
查询字符串= builder.buildQuery(列,选择,NULL,NULL,NULL,NULL);结果:
SELECT ROWID AS _id,suggest_text_1,suggest_text_2,ROWID AS suggest_intent_data_id
从FTS
WHERE(FTS匹配吗?)
选
和selectionArgs两个
参数是这样的创建字符串选择= FTS3_TABLE +匹配吗?
的String [] = selectionArgs两个新的String [] {*+查询+*};在RAW通过查询
builder.query导致同样的事情作为查询()
查询字符串= builder.buildQuery(列,选择,NULL,NULL,NULL,NULL);
光标TEMP = db.rawQuery(查询,selectionArgs两个);
字符串输出= DatabaseUtils.dumpCursorToString(TEMP);输出:>>>>>倾倒光标android.database.sqlite.SQLiteCursor@295023a7
<<<<<
解决方案http://stackoverflow.com/a/30710226/ 437039 通过laalto
匹配'*富*'
查询从来没有做过的正确的SQLite中的任何版本。你得到的事实的部分的结果是早期只是一个巧合。就在preFIX形式MATCH'富*'
(和MATCH'富'
)是的支持。
棒棒糖附带源码的更新版本。 SQLite的版本之间变化的详细列表,请参阅的changelog 。
块引用>The application has a
SearchView
which fetches suggestions from a specific database table. Everything worked without any errors until Android 5.0 appeared.As of then, when the
SQLiteQueryBuilder
queries the database to fill theCursor
object, the return is empty cursor. NotNULL
, but empty.On other platforms, I can output the
Cursor
's content viaDatabaseUtils.dumpCursorToString(cursorObject)
, but on Android 5.0+ the method reports output on null objectsDumping cursor null
<<<<<Even more: when I extract database file from 5.0+ devices and run the local SQL query, I can fetch all data. So the database is valid indeed. And the query is the simplest one
SELECT rowid AS _id, suggest_text_1, suggest_text_2, rowid AS suggest_intent_data_id FROM fts WHERE (fts MATCH '*e*') //<-- I pressed "e" on the keyboard
The logic for selecting data from the database and filling the
Cursor
object is really simpleSQLiteQueryBuilder builder = new SQLiteQueryBuilder(); builder.setTables(FTS3_TABLE); builder.setProjectionMap(mColumnMap); Cursor cursor = builder.query(db,columns, selection, selectionArgs, null, null, null);
I tried looking for some deprecated methods, but was without any luck.
I have already spent 3 days debugging each step in the process and I am out of any ideas what could be causing such behaviour.
Anyone has any ideas?
EDIT
The output of the method
buildQuery()
String query = builder.buildQuery(columns, selection, null, null, null, null); RESULT: SELECT rowid AS _id, suggest_text_1, suggest_text_2, rowid AS suggest_intent_data_id FROM fts WHERE (fts MATCH ?)
selection
andselectionArgs
parameters are created like thisString selection = FTS3_TABLE + " MATCH ?"; String[] selectionArgs = new String[]{"*" + query + "*"};
The RAW query resulted the same thing as query via
builder.query()
String query = builder.buildQuery(columns, selection, null, null, null, null); Cursor temp = db.rawQuery(query, selectionArgs); String output = DatabaseUtils.dumpCursorToString(temp); Output: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@295023a7 <<<<<
解决方案Answered http://stackoverflow.com/a/30710226/437039 by laalto
MATCH '*foo*'
queries never worked correctly in any version of sqlite. The fact that you got some results earlier was just a coincidence. Just the prefix formMATCH 'foo*'
(andMATCH 'foo'
) are supported.Lollipop ships with a newer version of sqlite. For detailed list of changes between sqlite versions, see the changelog.
这篇关于SQLiteDatabase光标空只能在Android 5.0+设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!