Friday, October 3, 2008

Android and sqlite3

Wow. For my new application which will go unnamed at the moment, I learned something very cool.

In the Eclipse Android SDK for Eclipse, there is a Perspective called DDMS. While your emulator (and application) is running, this will let you do all sorts of cool things. You can take a screenshot of what's showing on the phone. You can debug, look at logs, etc. It also shows you the filesystem for your application. Since your application is a its own Linux account, it has its own set of files and applications. And, if you are like mine and have persisted data using the built-in sqlite3 database, the database is also there on the filesystem. If your app is called foo.myapp then it's under /data/data/foo.myapp/databases.
There will be a file that is the name of the database along with any tables.

Let's say your database is called MyDatabase and you have a table, mytable.

Now click on the databases folder and click the action menu item for that view "Pull a file from this device". It will actually copy this whole directory to your local filesystem.

Now, hopefully at this point you are in Linux and already have sqlite3 installed. You do run Ubuntu right? :-)

Bring up a shell. Fire up sqlite3 like so:



That's it. It should list the contents of your table (assuming you have a column named col1). Other than that, it's standard sqlite3 stuff.

There should be a lot of neurons firing right now about what this means. Perhaps involving snycing. You can add files back to the device. And, this sort of thing can be done with a standalone emulator, so no eclipse is required.

Enjoy!

No comments: