0

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

在1中,我使用“match”,结果数为1。
在2中,我使用“=”,结果数为0。
在3中,我使用“=”和rawQuery()。结果数为 1。

我找不到问题。

4

1 回答 1

1

在 1 中,MATCH仅适用于字符串,因此它将wordId列的所有值转换为字符串并在它们中搜索字符串'65535'

在 2 中,您正在将wordId列中的值与字符串进行比较'65536'

在 3 中,您将wordId列中的值与数字进行比较65536

您应该仅将参数 ( selectionArgs) 用于字符串,而不是数字。

请注意,在 FTS 表上有效工作的唯一查询是使用/查找MATCH和查找。如果您需要其他查找,则说明您的数据库架构设计不正确。rowiddocid

于 2013-06-06T06:31:00.587 回答