This is my blog where I hope to post information about what I am doing technically and what my family is up to. I hope you enjoy

Tuesday, June 22, 2010

Displaying SQLite Data from Android Application

As I was building my Android application that uses an SQLite database I needed to determine what the actual data in the tables were due to the fact I had a bug in my application.   I need a tool like sqlplus, toad or PLSQL that enables one to peer into the tables.       I thought I could do this using the DDM perspective in the Eclipse Android plugin but this does not enable one to do so or rather I could not find a way to do this.

So here where the steps that I took to peer into my SQLite database tables.

First you need to get access to the SQLite database file where the information is stored.   Since I am building using Eclipse I Pull the file via the DDMS view within Eclipse.  The image below shows how this can be done within the Eclipse IDE.



After selecting on your database, in my case TASKS_DATABASE, you then select the Pull File you need to save it on your file system.   Pull File will grab the file from your emulater and place it onto you file system directory.

Once saved you need a tool that will help you peer inside this data.  I found a nice tool called SQLite Database Browser to do this exact task.    After unzipping the downloaded file.  Launch the database browser and Open the SQLite database file you just downloaded.   Here is a screen shot of the SQLite utility before loading the file I just pulled from Eclipse DDM view.


This shows three database tables within my SQLite database.  Choose the one you want to view and select on Browse Data.  This will display the contents of the data as shown below.



Use this tool to peer inside your data like you would with Oracle PL/SQL or Toad tools into Oracle.

Now I did this for the database that resides on the Emulator.   I believe you cannot do this to a database that reside on a real Android OS phone due to security reasons.  Or at least I hope not.


There is also another way to view what is in your SQLite tables via the adb shell and querying the database from the shell.

First need to get into the adb shell and cd to the directory where your applications database resides.
In this example I cd  data/data.

Now you need to cd to the application directory.
You will see the TASK_DATABASE file.  To get into the database you now execute the following.
>sqlite3 TASKS_DATABASE   shown below.

You can execute SQL to see what is in the tables.

No comments:

Post a Comment

Layout-->Edit HTML -->