我有一个没有返回任何值的SQL查询,但它有要返回的数据。以下查询代码
Cursor cursor = db.query(CrimeDB.NOME_TABELA, CrimeDB.COLUNAS,
CrimeDB.ID_CIDADE + "=" + idCidade + "" + " AND "
+ CrimeDB.TIME + " >= datetime('" + dataInicioFormatada
+ "') AND " + CrimeDB.TIME + " <= datetime('"
+ dataFimFormatada + "')" + " AND "
+ CrimeDB.GRUPO_CRIME + "=" + idCategoria + "", null,
null, null, null);
读取光标
if (cursor.moveToFirst()) {
do {
crime = new Crime();
crime.setLastUpadateToken(ultimoTokenValido
.getUltimoTokenAtualizado());
listCrime.add(itemCrime);
} while (cursor.moveToNext());
}
查询结果为:
SELECT
grupo_crime_id_grupo_crime,
id_crime,
cities_id_cities,
time
FROM
crime
WHERE
cities_id_cities=1650 AND
time >= datetime('20-10-2012') AND
time <= datetime('22-05-2014') AND
grupo_crime_id_grupo_crime=1
返回以实现任何值,因为数据库中存在值。使用SQLite编辑器,我看到表犯罪上的任何注册表。
id_crime | cities_id_cities | grupo_crime_id_grupo_crime | time
1 1650 1 28-03-2013
2 1650 1 06-04-2013
答案 0 :(得分:1)
使用yyyy/MM/dd
更改日期格式并尝试使用between
,而不是将日期与>=
和<=
进行比较。
答案 1 :(得分:0)
在检查where子句时使用撇号(')
Cursor cursor = db.query(CrimeDB.NOME_TABELA, CrimeDB.COLUNAS,
CrimeDB.ID_CIDADE + "='" + idCidade + "'" + " AND "
+ CrimeDB.TIME + " >= datetime('" + dataInicioFormatada
+ "') AND " + CrimeDB.TIME + " <= datetime('"
+ dataFimFormatada + "')" + " AND "
+ CrimeDB.GRUPO_CRIME + "='" + idCategoria + "'", null,
null, null, null);
答案 2 :(得分:0)
数据库和查询参数中的正确日期格式必须为yyyy-mm-dd
。