Inspecting SQLite Databases in Appcelerator Titanium Projects

If you’re using SQLite for your project and you’d like to query the database directly. For Android based devices or emulators, you can do the following:

~

If you’re using SQLite for your project and you’d like to query the database directly. For Android based devices or emulators, you can do the following:

You’ll need to remember your database name, if you’re using commonJS, you can do something similar to:

exports.getDatabase = function() {
    return Ti.Database.open('app.db');
};

Next, find out what devices you have connected using adb:

adb devices

This will return a list similar to this:

List of devices attached 
10.0.0.2:5555    device

Next, use the ADB shell command to boot into the device:

adb -s 10.0.0.2:5555 shell

This will drop you into a shell on the device. Next, find the database file. In the first code snippet here, you can see our database name is app.db, so we’ll use a combination of find and grep to find the file on the device:

cd /; find * | grep app.db

And this will return the SQLite file and it’s journal, like this:

root@vbox86p:/ # cd /; find * | grep app.db
data/data/com.example.audit/databases/app.db
data/data/com.example.audit/databases/app.db-journal

Now you can use the CLI tool to open the database, like so:

sqlite3 data/data/com.example.audit/databases/app.db

And you’ll be dropped into the CLI tool. You can get a list of tables by using .tables and exit the program via .quit.

The reference for this post came from this wonderful blog post.


~

Comments