1

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 the Cursor object, the return is empty cursor. Not NULL, but empty.

On other platforms, I can output the Cursor's content via DatabaseUtils.dumpCursorToString(cursorObject), but on Android 5.0+ the method reports output on null objects

Dumping 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 simple

    SQLiteQueryBuilder 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 and selectionArgs parameters are created like this

String 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
        <<<<<
7
  • what does buildQuery() return?
    – pskink
    Jun 5, 2015 at 14:31
  • i am referring to String buildQuery() method
    – pskink
    Jun 5, 2015 at 14:36
  • what is your selection and selectionArgs ?
    – pskink
    Jun 5, 2015 at 14:52
  • 1
    did you try to run that query using sqlite3 app on your device? or did you try to run SQLiteDatabase.rawQuery (String sql, String[] selectionArgs) ?
    – pskink
    Jun 5, 2015 at 15:02
  • if db.rawQuery() produces an empty Cursor them you will know why SQLiteQueryBuilder produces an empty Cursor, see androidxref.com/5.1.0_r1/xref/frameworks/base/core/java/android/…
    – pskink
    Jun 5, 2015 at 15:08

2 Answers 2

2

Answered https://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 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.

0

Have you tried to query using the SQLiteDatabase query method like the following?

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);
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.