SQLiteDatabase Cursor 仅在 Android 5.0+ 设备上为空

SQLiteDatabase Cursor empty only on Android 5.0+ devices

该应用程序有一个 SearchView 从特定数据库 table 获取建议。在 Android 5.0 出现之前,一切都没有任何错误。

至此,当SQLiteQueryBuilder查询数据库填充Cursor对象时,return为空游标。不是 NULL,而是空的。

在其他平台上,我可以通过 DatabaseUtils.dumpCursorToString(cursorObject) 输出 Cursor 的内容,但在 Android 5.0+ 上,该方法报告空对象上的输出

Dumping cursor null
<<<<<

甚至更多:当我从 5.0+ 设备和 运行 本地 SQL 查询中提取数据库文件时,我可以获取所有数据。所以数据库确实有效。而且查询是最简单的

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

从数据库中选择数据填充Cursor对象的逻辑非常简单

    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(FTS3_TABLE);
    builder.setProjectionMap(mColumnMap);

    Cursor cursor = builder.query(db,columns, selection, selectionArgs,
                                   null, null, null);

我尝试寻找一些已弃用的方法,但一无所获。

我已经花了 3 天时间调试过程中的每个步骤,但我不知道是什么导致了这种行为。

有人有什么想法吗?

编辑

方法的输出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 ?) 

selectionselectionArgs参数是这样创建的

String selection = FTS3_TABLE + " MATCH ?";
String[] selectionArgs = new String[]{"*" + query + "*"};

RAW 查询结果与通过 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
        <<<<<

您试过像下面这样使用SQLiteDatabase查询方式查询吗?

String selection = "fts" + " =? AND " +

 String[] selectionArgs = new String [] {
                "*e*"
        };
 String[] projection = new String [] { "rowId", "suggested_text"};
 SQLiteDatabase db = mDbHelper.getReadableDatabase();
 Cursor cursor = db.query("tableName",
                projection,selection, selectionArgs, null, null, null);

由 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 form MATCH 'foo*' (and MATCH 'foo') are supported.

Lollipop ships with a newer version of sqlite. For detailed list of changes between sqlite versions, see the changelog.