我的查询是
SELECT SUM(amount) AS total FROM transactions WHERE transaction_date > 1477333800
对于此查询,cursor.getCount()
正在返回1
。但是当迭代光标时,该值将变为空。
public Cursor getTotalForToday(long start)
{
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery("SELECT SUM(amount) AS total FROM "+TRANSACTION_TABLE+" WHERE transaction_date > "+start, null);
return c;
}
Cursor cursor = db.getTotalForToday();
if(cursor.getCount() == 0) // this is evaluating to false
{
forToday.setText("Zero"); //forToday is TextView
}
else
{
while(cursor.moveToNext())
{
String total_today = cursor.getString(0); // this is returning null
forToday.setText(total_today);
}
}
PS:amount
的数据类型在表
答案 0 :(得分:2)
聚合SQL函数(如sql
)始终返回结果行。结果本身可以为空。