使用where时,sqlite返回null

时间:2015-01-16 10:52:10

标签: android sqlite

我为此疯狂。如果我不使用'where',我的查询有效,但是当我插入'where'时,它什么都不返回。我确定'where'中指定的值确实存在。

这是我成功返回值的代码:

    Cursor cursor;
    cursor = database.query(MySQLiteHelper.TABLE_EVENTS, new String[] {"eventName, accountType"}, null, null, null, null, null);

    if (cursor.moveToFirst()) {
        do {
            Log.v(FILE_NAME, "eventName: " + cursor.getString(cursor.getColumnIndex("eventName")));
            Log.v(FILE_NAME, "accountType: " + cursor.getString(cursor.getColumnIndex("accountType")));
        } while (cursor.moveToNext());
    }

这是返回的值:

01-16 18:42:39.979 V/DbHelper.java﹕ 
V/DbHelper.java﹕eventName: Evenesis Gathering
V/DbHelper.java﹕accountType: 1
V/DbHelper.java﹕eventName: Asia Conference
V/DbHelper.java﹕accountType: 1

但是当我添加where值时:

Cursor cursor;
        cursor = database.query(MySQLiteHelper.TABLE_EVENTS, new String[] {"eventName, accountType"}, "accountType='1'", null, null, null, null);

        if (cursor.moveToFirst()) {
            do {
                Log.v(FILE_NAME, "eventName: " + cursor.getString(cursor.getColumnIndex("eventName")));
                Log.v(FILE_NAME, "accountType: " + cursor.getString(cursor.getColumnIndex("accountType")));
            } while (cursor.moveToNext());
        }

我一无所获。我做错了什么?

1 个答案:

答案 0 :(得分:2)

也许accountType是一个整数?如果是这样,抛弃报价:

cursor = database.query(MySQLiteHelper.TABLE_EVENTS,
        new String[] {"eventName, accountType"}, "accountType=1",
        null, null, null, null);