0
を返されている必要があります私はこのクエリのcursor.getCount(1)を返すが、0
SELECT SUM(amount) AS total FROM transactions WHERE transaction_date > 1477333800
でクエリを持って、cursor.getCount()
は1
を返しています。しかし、カーソルを反復するとき、値はnullになります。
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の拡張機能で同じことを照会した場合、私は、理想的には次のように出力
を取得しています返される行の数は0であるはずですが、なぜ1に戻っているのか分かりません。 ここにテーブルのデータがあります。
ダーン!これは私が今考え出したものです。最初のスクリーンショットの赤い色の背景は良いヒントでした。 – asprin