2

我经历了许多相关的线程,但我还没有成功。

我不知道我哪里出错了,我有以下方法来获取行。

    public Cursor getallrows (String fid , String sid , String bid , String pid , String limit)
    {
        return db.query(DATABASE_ALLPENLIST, new String[] {"rowpos","Peninnerid","issampled","onesymbol","twosymbol","threesymbol","foursymbol","fivesymbol","buildingid","farmid","sampleid","penid"}, "farmid = "+fid+" and sampleid = "+sid+" and buildingid = "+bid+" and penid = "+pid , null, null, null,"RANDOM()",limit);
    }

但是上面的方法返回了限制中提到的正确行数,但不是随机顺序,它返回限制变量中提到的前 n 行。

这是RANDOM()区分大小写的吗?但我也试过用Random()and"RANDOM() LIMIT "+limit代替第 7 个参数。

提前致谢 。

4

1 回答 1

1

如果变量是字符串类型,则此查询应与返回随机行一起使用,limit或者您可以像这样显式使用它:

db.query(DATABASE_ALLPENLIST, 
         new String[] {"rowpos","Peninnerid","issampled","onesymbol","twosymbol","threesymbol","foursymbol","fivesymbol","buildingid","farmid","sampleid","penid"}, 
         "farmid = "+fid+" and sampleid = "+sid+" and buildingid = "+bid+" and penid = "+pid ,
         null, 
         null, 
         null,
         "RANDOM()",
         "1");

或尝试原始查询:

db.rawQuery("Select rowpos, Peninnerid , issampled, onesymbol, twosymbol, threesymbol, foursymbol, fivesymbol, buildingid, farmid, sampleid, penid From " + DATABASE_ALLPENLIST + " Order By RANDOM() LIMIT ?", new String[] {limit});

此 API 的说明:链接

于 2013-07-20T06:51:14.507 回答