Debugging sqlite database on the device
I'll repeat myself from another answer:
Starting from API level 8 (Android 2.2), if you build the application as debuggable, you can use the shell
run-as
command to run a command or executable as a specific user/application or just switch to theUID
of your application so you can access its data directory.
So if you wish to pull your application database from the device you should run the debug build of the application, connect with adb shell
and run the following command:
run-as com.yourpackage sh -c "cat ~/databases/db-file" > /sdcard/db-file.sqlite
This will copy your db-file
to the root of your SD card / external storage. Now you can easily get it from there by using file manager, adb pull
or whatever else you like. Note that with this approach, there is NO need for your app to have WRITE_EXTERNAL_STORAGE
permission, as the copying is done by the shell user who can always write to the external storage.
On Linux/Mac systems there is a possibility to copy a database directly to your computer with the following command one can use without entering the adb shell:
adb shell 'run-as com.yourpackage sh -c "cat ~/databases/db-file"' > db-file.sqlite
This however will not work correctly on Windows because of CR/LF symbols conversion. Use the former method there.
Debugging a Database and SQLite file not consistent
Room uses write-ahead logging (WAL). Much of the time, this means that the SQLite database consists of three files:
- Whatever you named the base file
- One with
.wal
- One with
.shm
You need to copy all three if you wish to use the database elsewhere (e.g., desktop SQLite browser, backup/restore).
Debugging SQLite Database from Android App
There is an command-line version of sqlite3
available that allows you to directly access/view/modify an SQLite database in the adb (root) shell on the Android device without having to copy the database to your computer.
Of course you need root on the device, otherwise you can not access the app private directory with the database inside.
Edit: Some Android SQLite tools seem to implement something like an remote interface or a GUI for the command-line sqlite3 tool as described above. I have not tested it but SQLiteStudio in combination with it's DBAndroid plugin seem to provide GUI access from the PC to a database on the Android phone (without copying the database). Unfortunately the plugin is not free (commercial)
How to access my app's SQLite database in android device emulator for debugging
So i find this to be working:
adb root shell
adb shell
Then I'm able to navigate to my app's database folder and open it.
Sqlite plugin for Eclipse: debug sqlite database on Android device live
There is information on how to connect eclipse to a sqlite database here. Another alternative is using this Firefox add-on to manage your sqlite database.
How to debug SQLite database from SQLite Openhelper?
You can use the cursor
to see the content of your sqliteDb :
public Cursor selectRecords() {
String[] cols = new String[] {USER_ID, USER_NAME};
Cursor mCursor = database.query(true, USER_TABLE,cols,null
, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor; // iterate to get each value.
}
View sqflite table contents for debugging
Android Studio , Use Database Inspector as Code Poet Said
IntelliJ IDEA / DataGrip. you can choose Android SQLITE db, and it detect your connected devices.
IntelliJ Screenshot
*dont have enough reputation to post img
Related Topics
How to Create a Resizable Rectangle with User Touch Events on Android
Preventing Status Bar Expansion
Android Broadcast Receiver Bluetooth Events Catching
Send Data Back to the Script Which Started the Activity via Adb Shell Am Start
Download the Android Sdk Components for Offline Install
Using Resultreceiver in Android
How to Change Default Images of Checkbox
A Way to Get Unlock Event in Android
Error:Execution Failed For Task ':App:Transformclasseswithjarmergingfordebug'
How to Add Footer to Navigationview - Android Support Design Library
Ontaskremoved() Not Getting Called in Huawei and Xiaomi Devices
How to Create a Custom Notification Layout in Android
Ics Android Enable Gps Programmatically
Android Action Bar Not Showing Overflow