Domanda

1.

int mWordId = 65535;
String[] projection = {
    "wordId",
    "rank",
        };
String selection = "wordId MATCH ? ";
String[] selectionArgs = {Integer.toString(mWordId)};

Cursor c = pDatabase.query("words"
    ,projection
    ,selection
    ,selectionArgs
    ,null
    ,null
    ,"rank DESC");

c.moveToFirst();
int count= c.getCount();

2.

int mWordId = 65535;
String[] projection = {
    "wordId",
    "rank",
        };
String selection = "wordId =? ";
String[] selectionArgs = {Integer.toString(mWordId)};

Cursor c = pDatabase.query("words"
    ,projection
    ,selection
    ,selectionArgs
    ,null
    ,null
    ,"rank DESC");

c.moveToFirst();
int count= c.getCount();

3.

String query = "SELECT wordId,rank From words WHERE wordId=65535 ORDER BY rank DESC";
Cursor c = pDatabase.rawQuery(query,null);
c.moveToFirst();
int count= c.getCount();

In 1, I use "match" and the number of result is 1.
In 2, I use "=" and the number of result is 0.
In 3, I use "=" and rawQuery(). The number of result is 1.

I cant find the problem.

È stato utile?

Soluzione

In 1, MATCH works only with strings, so it converts all values of the wordId column to strings and searches them for the string '65535'.

In 2, you are comparing the values in the wordId column with the string '65536'.

In 3, you are comparing the values in the wordId column with the number 65536.

You should use parameters (selectionArgs) only for strings, not for numbers.

Please note that the only queries that work efficiently on FTS tables are lookups with MATCH and lookups on the rowid/docid. If you need other lookups, you database schema is not designed correctly.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top