Android sqlite - 选择字段为空或空的记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10465083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android sqlite - select records where field is null or empty
提问by Udi Idan
My application has an sqlite DB, where some of the fields are null or empty (meaning that I never inserted anything into that field).
我的应用程序有一个 sqlite 数据库,其中一些字段为 null 或为空(这意味着我从未在该字段中插入任何内容)。
I wish to select all the records for which the field is null or empty.
我希望选择该字段为空或空的所有记录。
This is what I have tried:
这是我尝试过的:
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, "folder_name = ? ", new String[] {"null"}, null, null, DBHelper.TIMESTAMP_COL + " DESC");
But that didn't work, and I didn't get any records. What do I need to do to make this work?
但这不起作用,我没有得到任何记录。我需要做什么才能完成这项工作?
回答by Rayne
Try
尝试
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, "folder_name is null or folder_name = ?", new String[] {""}, null, null, DBHelper.TIMESTAMP_COL + " DESC");
回答by Yaqub Ahmad
db.rawQuery("SELECT * FROM myTable WHERE myColumn IS NULL", null);
回答by Abraham Mathew
I am using android studio 3.4, Room 2.1.0-alpha07
我正在使用 android studio 3.4,房间 2.1.0-alpha07
This is my Kotlin Code
I tried using this didn't work as expected
这是我
尝试使用的Kotlin 代码,但没有按预期工作
`@Query("SELECT *FROM notifications WHERE status=:status OR status = null")`
This one is working fine
这个工作正常
@Query("SELECT *FROM notifications WHERE status=:status OR status is null")
回答by Evgeny Nacu
Just use "folder_name is null"
只需使用“文件夹名称为空”