I am getting a null cursor with a particular query in sqlite. The query is
SELECT type, SUM(amount) FROM tran WHERE strftime('%Y%m',tran_date) = strftime('%Y%m','2015-02-20') AND exclude = 0 GROUP BY type;
I have tried using raw query and the standard query but both bring back a null cursor and after chopping the query around it seems to be because of the GROUP BY clause. If I enter this query into SQLite Manager using my database the row is returned as expected. Below is the code that I am trying:
Cursor cursor = database.query(TABLE_TRANSACTION,
new String[]{ COLUMN_TYPE, "SUM(" + COLUMN_AMOUNT + ")" },
"strftime('%Y%m',tran_date) = strftime('%Y%m',?) AND exclude = 0",
new String[] { "'" + Utilities.convertCalendarToString(date, Constants.FORMAT_YYYY_MM_DD) + "'" },
COLUMN_TYPE,
null,
null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
if (Constants.INCOME.equals(cursor.getString(0))) {
summary.put(Constants.INCOME, cursor.getDouble(1));
} else if (Constants.EXPENSE.equals(cursor.getString(0))) {
summary.put(Constants.EXPENSE, cursor.getDouble(1));
}
}
cursor.close();
Aucun commentaire:
Enregistrer un commentaire