lundi 17 août 2015

How get data by month using SQLite in Android

I'm facing some problems trying get a list of months and a list of data by month from my database in my app. Now I'm using strftime() function from SQLite but apparently the strftime() doesn't work. For building and managing the database I'm using DBFlow ORM and the query of the first list looks like that.

List<ExpenseAndIncome> expenseAndIncomes = new Select("strftime('%Y-%m-%d', date").from(ExpenseAndIncome.class).queryList();

SELECT `strftime('%Y-%m-%d', date)` FROM `expense_and_income` 

In this case it shows up an exception

android.database.sqlite.SQLiteException: no such column: strftime('%Y-%m-%d', date) (code 1): , while compiling: SELECT `strftime('%Y-%m-%d', date)` FROM `expense_and_income`

The other problem occurs when I'm trying to get a list of data by month. In this case the query looks like that.

List<ExpenseAndIncome> expenseAndIncomes = new Select().from(ExpenseAndIncome.class).where("strftime('%m', date) = ?", calendar.get(Calendar.MONTH)).groupBy("date").queryList();

SELECT * FROM `expense_and_income` WHERE strftime('%m', date) = 7 GROUP BY date 

But the result always is a empty array.

Can someone helpe me?

Aucun commentaire:

Enregistrer un commentaire