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.).
SQLite Database is an open-source database provided in Android which is used to store data inside the user's device in the form of a Text file. We can perform so many operations on this data such as adding new data, updating, reading, and deleting this data.
moveToNext(): Moves the cursor to the next row relative to the current position. boolean Cursor.
A Cursor represents the result of a query and basically points to one row of the query result. This way Android can buffer the query results efficiently; as it does not have to load all data into memory. To get the number of elements of the resulting query use the getCount() method.
You need to check if it's null yourself.
Long l = null;
if (!cursor.isNull(7))
l = cursor.getLong(7);
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