Not sure if I\'m the only one who feels this...
I find working with the sqlite api in android a complete pain in the butt and pretty soul destroying. Has anyone got
Cursor
, rather than trying to pass in umpteen parameters.query()
is much more verbose than rawQuery()
for limited added value, if you know SQL.CREATE TABLE
clause via concatenation is self-imposed pain, not mandated by SQLite or Android.getColumnIndexOrThrow()
from custom-written code. You wrote the query, so you know what order the columns are coming back in. Only use something like getColumnIndexOrThrow()
if you are creating some abstract library that does not know the details of the Cursor it was given.String
inherits from CharSequence
, so all those casts can be dropped.I tested a lot of my SQL in SQLite before copying them over to Android as strings. It's easier for me to debug when I can directly interact with the command line.
Another technique I use is saving as much of my queries as possible as string constants or string resources.
You also don't need SQL such as INTEGER NOT NULL
since SQLite uses duck typing/manifest typing. It does help for type affinity though..