游标未返回所有值

时间:2018-12-02 17:04:42

标签: android sqlite android-sqlite

每当我尝试获取对应的序列号为no的行时,光标都会返回除那一行之外的所有行。我可能会丢失一些愚蠢的东西但无法找到。请帮助我。

public TimeTable getOneRecord(int dateId) {
    db = this.getReadableDatabase();
    Log.d(TAG, "insie getOneRecord  " + dateId);
    Cursor cursor = db.query(TABLE_USER, new String[]{COLUUMN_ID, COLUMN_INTIME, COLUMN_OUTTIME},
            COLUUMN_ID + "-?", new String[]{String.valueOf(dateId)}, null, null, null);
    if (cursor != null) {
        Log.v(TAG, DatabaseUtils.dumpCursorToString(cursor));
        cursor.moveToFirst();
    }

    TimeTable timeTable = new TimeTable(cursor.getInt(cursor.getColumnIndex(COLUUMN_ID)),
            cursor.getString(cursor.getColumnIndex(COLUMN_INTIME)),
            cursor.getString(cursor.getColumnIndex(COLUMN_OUTTIME)));
    Log.d(TAG, " in time : " + timeTable.getInTime());
    Log.d(TAG, " Date : " + timeTable.getSerialNo());

    // close the db connection
    cursor.close();
    return timeTable;
}

表中总共有3条记录,当我尝试获取第二行的值时,日志将显示此记录。

D/Main Activity 124: insie getOneRecord  2
Dumping cursor android.database.sqlite.SQLiteCursor@d643fee
    0 {
       SRNo=1
       INTime=02:08 PM
       OUTTime=null
    }
    1 {
       SRNo=3
       INTime=02:21 PM
       OUTTime=null
    }
    <<<<<
total records 3
     serial no -- 1 in time -- 02:08 PM out time -- null
     serial no -- 2 in time -- 10:23 PM out time -- 10:23 PM
     serial no -- 3 in time -- 02:21 PM out time -- null

0 个答案:

没有答案