To quickly test your SQLite database while developing an Android app, it can be useful to use the sqlite3 command line command to query the database. However, it is not easy to get to the SQLite file: you cannot just download it from your device, nor can you mount the right directory to your development machine.

Luckily, the handy adb shell comes to the rescue. There is no copy possibility easy to the external card or whatever, only cat. To get the file onto your computer, use these two steps:

~$ adb shell "run-as <package> \
           cat /data/data/<package>/databases/<database>" > \
           /sdcard/<database>
~$ adb pull /sdcard/<database>

where <package> is the package name of your app, as found in the AndroidManifest.xml (the package attribute in the manifest (root) tag. <database> is the database name you used in the constructor of your SQLiteOpenHelper.

Update it seems that not all devices support this method (starting from Android 5.0?), so there is another way to do it: first allow full read access to the file and then pull directly:

~$ adb shell "run-as <package> \
           chmod 666 /data/data/<package>/databases/<database>"
~$ adb pull /data/data/<package>databases/<database>

then, you use sqlite3 to query anything from there:

~$ sqlite3 <database>
sqlite> select * from <table>;
1|3|foo
3|6|bar

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.