0

我有一个不返回任何值的 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
4

3 回答 3

1

更改日期格式yyyy/MM/dd并尝试使用 和 来代替between比较日期。>=<=

于 2013-05-08T17:07:12.230 回答
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);
于 2013-05-08T16:38:49.020 回答
0

数据库和查询参数中的正确日期格式必须是yyyy-mm-dd.

于 2013-05-08T17:03:17.167 回答