The ContentValues class contains a method that allows Booleans to be put into the values collection. AFAIK, SQLite does not contain a native Boolean format that Android could push the boolean values into. So, what magic does Android do behind the scenes to store these values?
Also, why is there no complimentary getBoolean method on a Cursor? To me, this appears to be a pretty awkward design oversight since there seems to be no "safe" way of retrieving a boolean value that was put into the DB via ContentValues. What am I missing?
This question may seem a bit frivolous since I suspect that the boolean's are stored as a 1 or 0 integer, but why would Android commit to developers making that assumption? Its not even documented as far as I am aware.
This class is used to store a set of values that the ContentResolver can process.
ContentValues is a maplike class that matches a value to a String key. It contains multiple overloaded put methods that enforce type safety. Here is a list of the put methods supported by ContentValues: void put(String key, Byte value) void put(String key, Integer value)
The ContentValues class contains a method that allows Booleans to be put into the values collection. AFAIK, SQLite does not contain a native Boolean format that Android could push the boolean values into. So, what magic does Android do behind the scenes to store these values?
From reading this document, it sounds like the boolean to integer conversion is done by SQLite.
Also, why is there no complimentary getBoolean method on a Cursor? To me, this appears to be a pretty awful design oversight since there seems to be no "safe" way of retrieving a boolean value that was put into the DB via ContentValues. What am I missing?
If you're reading from a cursor, then you know what columns should be returned from the query, so you presumably know the data types of the columns that were requested. I agree that having a getBoolean
method would be better, but it's not hard to work around.
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