cursor.getCount()返回1,但应该返回0

时间:2016-10-25 07:51:29

标签: java android

我的查询是

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的数据类型在表

中是整数

如果我在SQLLite Firefox扩展中查询相同的内容,我得到以下输出 SS1

理想情况下,返回的行数应为0,但我不知道它为什么返回为1。 这是btw表中的数据: SS2

1 个答案:

答案 0 :(得分:2)

聚合SQL函数(如sql)始终返回结果行。结果本身可以为空。

相关问题