在 SQLite 查询中使用 LIMIT 语句 [英] Using the LIMIT statement in a SQLite query
问题描述
我有一个查询,可以在没有限制的情况下选择 ListView
中的行.但是现在我已经实现了一个 SharedPreferences
,用户可以选择在 ListView
中显示多少行,我的 SQLite 查询不起作用.我是这样传递论点的:
return wDb.query(TABELANOME, new String[] {IDTIT, TAREFATIT, SUMARIOTIT}, CONCLUIDOTIT + "=1", null, null, null, null, "LIMIT='" + limite + "'");
等号 (=
) 运算符不与 LIMIT
子句一起使用.删除它.
这是一个 LIMIT
查询示例:
SELECT column FROM table ORDER BY somethingelse LIMIT 5, 10
或者:
SELECT column FROM table ORDER BY somethingelse LIMIT 10
在你的情况下,正确的说法是:
return wDb.query(TABELANOME, new String[] {IDTIT, TAREFATIT, SUMARIOTIT}, CONCLUIDOTIT + "=1", null, null, null, null, String.valueOf(limite));
看看这里的 SQLite 选择语法:http://www.sqlite.org/syntaxdiagrams.html#select-stmt
这张图片相当有用:http://www.sqlite.org/images/syntax/select-stmt.gif>
I have a query that selects rows in a ListView
without having a limit. But now that I have implemented a SharedPreferences
that the user can select how much rows will be displayed in the ListView
, my SQLite query doesn't work. I'm passing the argument this way:
return wDb.query(TABELANOME, new String[] {IDTIT, TAREFATIT, SUMARIOTIT}, CONCLUIDOTIT + "=1", null, null, null, null, "LIMIT='" + limite + "'");
The equals (=
) operator is not used with the LIMIT
clause. Remove it.
Here's an example LIMIT
query:
SELECT column FROM table ORDER BY somethingelse LIMIT 5, 10
Or:
SELECT column FROM table ORDER BY somethingelse LIMIT 10
In your case, the correct statement would be:
return wDb.query(TABELANOME, new String[] {IDTIT, TAREFATIT, SUMARIOTIT}, CONCLUIDOTIT + "=1", null, null, null, null, String.valueOf(limite));
Take a look here at the SQLite select syntax: http://www.sqlite.org/syntaxdiagrams.html#select-stmt
This image is rather useful: http://www.sqlite.org/images/syntax/select-stmt.gif
这篇关于在 SQLite 查询中使用 LIMIT 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!