SQLite游标在使用where时返回空光标

时间:2014-10-15 14:34:11

标签: android sqlite

使用以下代码

resultSet = mydatabase.rawQuery("Select * from devicelog  ", null);
        Log.e("SyncService", "query fiered..");
        if (resultSet.moveToFirst()) {
            Log.e("SyncService", "moved to first..");
            do {
                Log.e("DB_R", "id: " + resultSet.getInt(resultSet.getColumnIndex("id")));
                Log.e("DB_R", "type: " + resultSet.getString(resultSet.getColumnIndex("type")));
                Log.e("DB_R", "action: " + resultSet.getString(resultSet.getColumnIndex("action")));
                Log.e("DB_R", "oldvalue: " + resultSet.getString(resultSet.getColumnIndex("oldvalue")));
                Log.e("DB_R", "newvalue: " + resultSet.getString(resultSet.getColumnIndex("newvalue")));
                Log.e("DB_R", "devicedt: " + resultSet.getString(resultSet.getColumnIndex("devicedt")));
                Log.e("DB_R", "batterysts: " + resultSet.getDouble(resultSet.getColumnIndex("batterysts")));
                Log.e("DB_R", "syncdt: " + resultSet.getString(resultSet.getColumnIndex("syncdt")));
                Log.e("DB_R", "deviceid: " + resultSet.getString(resultSet.getColumnIndex("deviceid")));
            } while (resultSet.moveToNext());
        }
        if (resultSet != null && !resultSet.isClosed()) {
            resultSet.close();
        }

        if (mydatabase != null && mydatabase.isOpen()) {
            mydatabase.close();
        }
        Log.e("SyncService", "query closed..");

我在adb logcat中得到以下输出

10-15 19:46:33.233: E/SyncService(2446): b4 try..
10-15 19:46:33.294: E/SyncService(2446): query fiered..
10-15 19:46:33.294: E/SyncService(2446): moved to first..
10-15 19:46:33.324: E/DB_R(2446): id: 1
10-15 19:46:33.324: E/DB_R(2446): type: SETTINGS
10-15 19:46:33.324: E/DB_R(2446): action: IP changed
10-15 19:46:33.333: E/DB_R(2446): oldvalue: 0.0.0.0:0
10-15 19:46:33.333: E/DB_R(2446): newvalue: 10.20.30.40:50
10-15 19:46:33.333: E/DB_R(2446): devicedt: 2014-10-15 11:01:40
10-15 19:46:33.355: E/DB_R(2446): batterysts: 0.5
10-15 19:46:33.355: E/DB_R(2446): syncdt: null
10-15 19:46:33.355: E/DB_R(2446): deviceid: e4:2d:02:0f:8f:4a
10-15 19:46:33.355: E/SyncService(2446): query closed..

因此,syncdt = null存在一条记录。但是当我使用相同的代码触发查询后

resultSet = mydatabase.rawQuery("Select * from devicelog where syncdt = null ", null);

我的空光标如下:

10-15 19:50:49.957: E/SyncService(2530): b4 try..
10-15 19:50:50.117: E/SyncService(2530): query fiered..
10-15 19:50:50.157: E/SyncService(2530): query closed..

我使用错误的方法检查空值吗?

1 个答案:

答案 0 :(得分:1)

要在使用is null的位置获取空值,请从

更改查询
resultSet = mydatabase.rawQuery("Select * from devicelog where syncdt = null ", null);

resultSet = mydatabase.rawQuery("Select * from devicelog where syncdt is null", null);