sqlite returns null 在使用 where 时
sqlite returns null when using where
我快要为这个疯狂了。如果我不使用 'where',我的查询就有效,但是当我插入 'where' 时,它 returns 什么也没有。我非常确定 'where' 中指定的值确实存在。
这是我成功 returns 值的代码:
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());
}
我什么都没有。我做错了什么吗?
也许accountType是一个整数?如果是这样,请放弃引号:
cursor = database.query(MySQLiteHelper.TABLE_EVENTS,
new String[] {"eventName, accountType"}, "accountType=1",
null, null, null, null);
我快要为这个疯狂了。如果我不使用 'where',我的查询就有效,但是当我插入 'where' 时,它 returns 什么也没有。我非常确定 'where' 中指定的值确实存在。
这是我成功 returns 值的代码:
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());
}
我什么都没有。我做错了什么吗?
也许accountType是一个整数?如果是这样,请放弃引号:
cursor = database.query(MySQLiteHelper.TABLE_EVENTS,
new String[] {"eventName, accountType"}, "accountType=1",
null, null, null, null);