Using SQLite with the Android emulator and Eclipse

One of the ways of persisting data with Android is to use a SQLite database. A fuller list of methods is given here. When you are persisting data in any application one of the things you will want to do is write ad hoc queries to see is you data getting to the database, how big are your tables etc. SQLLite lets you do this with the databases that your applications use in the emulator. You will need to connect to the emulator using the Android Debug Bridge (adb). Type this at a command prompt (you obviously need to have adb.exe on your path, or just open a command prompt in the tools directory of your android installation - \android-sdk-windows\tools in my case):


adb -s emulator-5554 shell

The name of your emulator may be different, you can check the name in the console of eclipse when you are launching an app to run on the emulator.
Once you have run that you will need to use the sqlite3 command to mount the database you are interested in. Enter this at the shell prompt which you just opened:

sqlite3 path_to_your_db_file

To find out what that path is open the DDMS perspective in eclipse. There is a file explorer tab. Under this there will be a folder called data. This contains another folder called data which in turn contains a folder named after the package name that you used setting up your project. In my case com.nolantech. Inside that is another folder called databases and finally the file you are interested. The file name is the one you will have assigned in code when you first opened the database. So for me that is all:

sqlite3 /data/data/com.nolantech/databases/data

You are then able to examine your tables (enter .tables for a list) using normal SQL syntax.
Note that any commands that you enter here which are preceded by a . are SQLite commands. They are run by the shell. Any other commands are database commands and are passed from the shell to the underlying database library for handling.
Type .help for a fuller list of what you can do.

Comments

Popular posts from this blog

AutoCompleteTextView backed with data from SQLite in Android

Building a choropleth map for Irish agricultural data

Using Statistics to Hire Developers