Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android sqlite - select records where field is null or empty

Tags:

android

sqlite

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?

like image 312
Udi Idan Avatar asked May 05 '12 19:05

Udi Idan


People also ask

Is NULL or empty in SQLite?

SQLite IS NOT NULL operator.

How do I use Isnull in SQLite?

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.

Where is NULL in SQLite?

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.

How can I tell if SQLite database is empty Android?

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.


1 Answers

Try

cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, "folder_name is null or folder_name = ?", new String[] {""}, null, null, DBHelper.TIMESTAMP_COL + " DESC"); 
like image 124
Rayne Avatar answered Oct 14 '22 04:10

Rayne