user2707175
user2707175

Reputation: 1137

android cursor how to get null values from columns

I keep all data to be stored in database as Objects (ex. instead of int I use Integer) in order to keep null values.

When saving data to SQLite database if Object is null I use:

statement.bindNull(index);

When I look at my database using aSQLiteManager it seems that values are correctly stored (empty field for Long column with null value).

However how to read value from cursor keeping null information?

If I use:

cursor.getLong(7)

for column where I have null, instead of null I get 0. It's not surprising as getLong returns long type value, not Long. However I'm not able to find any function returning Long. Any help? Of course I need also get functions keeping null values for other Objects (Integer, String etc.).

Upvotes: 14

Views: 7946

Answers (1)

Graham Borland
Graham Borland

Reputation: 60681

You need to check if it's null yourself.

Long l = null;
if (!cursor.isNull(7))
    l = cursor.getLong(7);

Upvotes: 42

Related Questions