Tin*_*iny 0 sqlite android count
我正在尝试从Sqlite数据库检索行的总数。我使用了以下代码,但问题是即使有多于一行满足条件,计数也始终为1。谁能指导我哪里出问题了。
public int get_report_entry_area_count(String jobId, String area,
String sensor) {
String countQuery = "select count(*) from report1 where JobId='"
+ jobId + "' and sensor='" + sensor + "'" + " and Area='"
+ area + "'";
SQLiteDatabase database = this.getWritableDatabase();
Cursor c = database.rawQuery(countQuery, null);
c.moveToFirst();
int total = c.getCount();
c.close();
return total;
}
Run Code Online (Sandbox Code Playgroud)
使用计数总是在Android sqlite中返回1
因为c.getCount()返回的项数是提供的Cursor而不是count查询结果。
从获取计数结果Cursor:
c.moveToFirst();
int total = c.getInt(0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
704 次 |
| 最近记录: |