views:

334

answers:

1

I have a SQLite database, and several tables within that datbase. I am developing a DBAdapter for each table within the database. (reference Reto Meier's Professional Android 2 Application Development, Listing 7.1).

I am using the adb shell to interface with the database from the command line and see that the database is being populated as I expect. Occasionally, I want to drop a table so that I can ensure it's being built properly, from scratch.

The problem is that SQLiteOpenHelper only checks to see if the database exists. Is there a typical solution to writing a helper to also see that the table(s) exists? Basically once I drop a table, the helper checks to see that the database exists and assumes all is well.

Also, the CREATE_DATABASE string used in the reference above only creates the one table. Should I consider using the DBAdapter for an adapter to ALL of my tables? That doesn't seem as clean to me.

Reference Material

+1  A: 

Is there a typical solution to writing a helper to also see that the table(s) exists?

SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='...' ORDER BY name;

(substituting in your table's name for ...)

If that returns 1, your table exists. If that returns 0, your table does not exist.

However, the helper won't help you with that. For testing purposes, I recommend getting rid of the entire database, since in production, you won't be creating individual tables on the fly, either.

CommonsWare
So, I really feel dumb..but what's the shell command to get rid of the db?
tunneling
`rm /data/data/your.package.here/databases/your.db`, substituting in appropriate values for `your.package.here` and `your.db`. Or, use the File Manager in DDMS (standalone or Eclipse perspective) and nuke it that way.
CommonsWare