0

I have a sql query that is not returning any value, but it has data to be returned. The following query code

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

Read cursor

if (cursor.moveToFirst()) {

        do {
            crime = new Crime();
            crime.setLastUpadateToken(ultimoTokenValido
                    .getUltimoTokenAtualizado());

            listCrime.add(itemCrime);

        } while (cursor.moveToNext());

    }

The query result is:

    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

was returns to realize any value because there is value in the database. Using the SQLite Editor I see any register on the table crime.

id_crime | cities_id_cities | grupo_crime_id_grupo_crime | time
1          1650               1                            28-03-2013
2          1650               1                            06-04-2013
2
  • is your idCidade integer value ? Commented May 8, 2013 at 16:59
  • Yes, I do. idCidade is integer value. Commented May 8, 2013 at 17:03

3 Answers 3

1

Change the date format with yyyy/MM/dd and try using between instead of comparing dates with >= and <=.

Sign up to request clarification or add additional context in comments.

Comments

0

use apostrophe (') while checking in where clause

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

1 Comment

tested that way and it made no difference :(
0

The proper date format, both in the database and in your query parameters, must be yyyy-mm-dd.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.