android-developers - BUG in SQLite? Cannot use Long Integers in Cache Database

by Jeffon 2010-04-13T14:18:49+00:00
Has anyone been able to get Long Integers to work with a SQLite DB on
Android?
In particular, I am noticing some odd behavior with Webkit's Cache
Database. The "expires" column is always 0. After doing some testing,
I realized that SQLite will accept a value in the "expires" column up
to (2^31 - 1). Anything higher than this, and the value is always 0.
The cache database uses Date.getTime() to populate this field. Since
this is a long, the value is always 0.
Is this a bug in the Cache Database or the SQLite implementation?
Jeff
Here is a list of data types that are allowed in SQLite 3:
http://www.sqlite.org/datatype3.html
Note that there is no official "long" data type. It would be classified as
INTEGER or REAL. For actual "long" data types that don't seem to be stored
well in SQLite you might do better to store as TEXT and do a conversion
outside of SQLite.
I am by no means a database expert though, perhaps someone with more SQLite
experience will chime in with a better explanation.
Justin
Has anyone been able to get Long Integers to work with a SQLite DB on
Android?
In particular, I am noticing some odd behavior with Webkit's Cache
Database. The "expires" column is always 0. After doing some testing,
I realized that SQLite will accept a value in the "expires" column up
to (2^31 - 1). Anything higher than this, and the value is always 0.
The cache database uses Date.getTime() to populate this field. Since
this is a long, the value is always 0.
Is this a bug in the Cache Database or the SQLite implementation?
Jeff


I spent 2 days trying to figure this out, and wouldn't you know it...2
minutes after posting to the group, I think I have figured out what I was
doing wrong.
In order to check my work, I was exporting the database to my local computer
and opening it with SQLite Administrator. The values were appearing as 0
because the "affinity" of this column in the database was set as INTEGER. So
it while is appeared that these values were getting stored as 0, in
actuality they were just getting displayed as 0 in SQLite Administrator.
The true value of these fields are indeed getting stored properly. I just
had to CAST(expires as NUMERIC) in order to view them.
Sorry for the false alarm.

The true value of these fields are indeed getting stored properly. I just had to CAST(expires as NUMERIC) in order to view them.