My application has an sqlite DB, where some of the fields are null or empty (meaning that I never inserted anything into that field).
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?
SQLite IS NOT NULL operator.
SQLite ifnull() functionThe ifnull() function returns a copy of its first non-NULL argument, or NULL if both arguments are NULL. Ifnull() must have exactly 2 arguments. The ifnull() function is equivalent to coalesce() with two arguments.
SQLite NULL is the term used to represent a missing value. A NULL value in a table is a value in a field that appears to be blank. A field with a NULL value is a field with no value.
To determine whether an SQLite database file is empty, execute the following query: SELECT COUNT(*) FROM sqlite_schema; You will get the number of objects (tables, indices, views, triggers) in the database or 0 if the file is empty.
Try
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, "folder_name is null or folder_name = ?", new String[] {""}, null, null, DBHelper.TIMESTAMP_COL + " DESC");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With