I need to view my SQLite db but I don't know how to do it. I've gone to http://www.sqlite.org/download.html and downloaded the command line shell for my OS, but when I run the program and type adb ...
I get errors.
Note: I'm using Android Studio so I'm assuming I don't need to install anything extra because I recall Android Studio said it had all the SDK tools needed.
What it mentions as you type adb?
cd <ANDROID_SDK_PATH>
(for me on Windowscd C:\Users\Willi\AppData\Local\Android\sdk
)cd platform-tools
adb shell
(this works only if only one emulator is running)cd data/data
su
(gain super user privileges)cd <PACKAGE_NAME>/databases
sqlite3 <DB_NAME>
;
, otherwise the statement is not issued and it breaks to a new line instead.)Note: Use
ls
(Linux) ordir
(Windows) if you need to list directory contents.Easiest Way: Connect to Sqlite3 via ADB Shell
I haven't found any way to do that in Android Studio, but I access the db with a remote shell instead of pulling the file each time.
Find all info here: http://developer.android.com/tools/help/sqlite3.html
1- Go to your platform-tools folder in a command prompt
2- Enter the command
adb devices
to get the list of your devices3- Connect a shell to your device:
4a- You can bypass this step on rooted device
4b- Navigate to the folder containing your db file:
5- run sqlite3 to connect to your db:
6- run sqlite3 commands that you like eg:
SQLite cheatsheet
There are a few steps to see the tables in an SQLite database:
List the tables in your database:
List how the table looks:
Print the entire table:
List all of the available SQLite prompt commands:
The issue you are having is common and not explained well in the documentation. Normal devices do not include the sqlite3 database binary which is why you are getting an error. the Android Emeulator, OSX, Linux (if installed) and Windows (after installed) have the binary so you can open a database locally on your machine.
The workaround is to copy the Database from your device to your local machine. This can be accomplished with ADB but requires a number of steps.
Before you start you will need some information:
<package name>
, for example,com.example.application
<local path>
to place your database, eg.~/Desktop
or%userprofile%\Desktop
Next you will need to understand what terminal each command gets written to the first character in the examples below does not get typed but lets you know what shell we are in:
>
= you OS command prompt$
= ADB shell command Prompt!
= ADB shell as admin command prompt%
Next enter the following commands from Terminal or Command (don't enter first character or text in
()
)This is a really round about way of copying the database to your local machine and locally reading the database. There are SO and other resources explaining how to install the sqlite3 binary onto your device from an emulator but for one time access this process works.
If you need to access the database interactively I would suggest running your app in an emulator (that already had sqlite3) or installing sqlite onto your devices /xbin path.
Easiest way for me is using Android Device Monitor to get the database file and SQLite DataBase Browser to view the file while still using Android Studio to program android.
1) Run and launch database app with Android emulator from Android Studio. (I inserted some data to database app to verify)
2) Run Android Device Monitor. How to run?; Go to
[your_folder] > sdk >tools
. You can see monitor.bat in that folder.shift + right click
inside the folder and select "Open command window here
". This action will launch command prompt. typemonitor
and Android Device Monitor will be launched.3) Select the emulator that you are currently running. Then Go to
data>data>[your_app_name]>databases
4) Click on the icon (located at top right corner) (hover on the icon and you will see "pull a file from the device") and save anywhere you like
5) Launch SQLite DataBase Browser. Drag and drop the file that you just saved into that Browser.
6) Go to
Browse Data
tab and select your table to view.Depending on devices you might not find sqlite3 command in adb shell. In that case you might want to follow this :
adb shell
for reference go to https://stackoverflow.com/a/17177091/3758972.
There might be cases when you get "remote object not found" after following above procedure. Then change permission of your database folder to 755 in adb shell.
But please mind that it'll work only on android version < 21.