How to extract sqlite database from android device using ADB? [duplicate] - android

This question already has answers here:
Retrieve database or any other file from the Internal Storage using run-as
(12 answers)
Closed 4 years ago.
I followed the step by step instructions given in the answer of How do I view the SQLite database on an Android device?
1) Connect your device and launch the application in debug mode.
2) Copy the database file from your application folder to your sd
card. You may want to use adb -d shell "run-as com.resmed.mon ls
/data/data/com.resmed.mon/databases/" to see what the database
filename is.
3) adb -d shell "run-as com.yourpackge.name cat
/data/data/com.yourpackge.name/databases/filename.sqlite >
/sdcard/filename.sqlite"
(in my case "/data/data/com.mypackge.name/databases/MyDb")
4) Pull the database files to your machine:
5) adb pull /sdcard/filename.sqlite .
6) Install Firefox SQLLite Manager:
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
7) Open Firefox SQLLite Manager (Tools->SQLite Manager) and open your
database file from step 3 above."
But in my case, the database extracted is always empty. When i open the file on SQL Lite Manager, i can't find my tables and my data. I don't understand why. I can see the data on my device screen using my app in debug mode. Is there an other folder where my database could be stored ?
My phone is not rooted.
Thanks for your help.
PS : I wanted to comment on the previous answer, but my reputation is too low to interact with the answer.

I've published a simple shell script for dumping databases:
https://github.com/Pixplicity/dbdump
It performs two distinct methods described here:
First, it tries to make the file accessible for other users, and attempting to pull it from the device.
If that fails, it streams the contents of the file over the terminal to the local machine. It performs an additional trick to remove \r characters that some devices output to the shell.
From here you can use a variety of CLI or GUI SQLite applications, such as sqlite3 or sqlitebrowser, to browse the contents of the database.

As far as I remember, you shouldn't be able to extract a database from un-rooted device. You can however get it from an emulator!

Related

How fast extract db file from Android device? [duplicate]

This question already has answers here:
Retrieve database or any other file from the Internal Storage using run-as
(12 answers)
Closed 4 years ago.
In my Android project I use Realm.
Sometimes I need to extract db file from device.
To do this I follow the next steps:
Open console
adb shell
run-as my_project_name_space
cd files
cp my_db_file.realm /sdcard
exit
exit
adb pull sdcard/my_db_file.realm d:\Temp\my_db_file.realm
As result in folder d:\Temp I get db file: my_db_file.realm
Nice. It's work fine.
But when I need again to extract db file I must again do all of this 8 steps.
Has any faster approach?
Something like start script that execute all of this 8 steps. Or or something similar.
Thanks.
In debug apk you can use android studio's device explorer
goto path
/data/data/your-package-name/files/your-db.realm
and by right clicking you can save it without running any kind of code.

How to view sqlite database using real device

I've been searching this for quite a long time and I found the following steps at https://stackoverflow.com/a/24259250/5256621
1.Connect your device and launch the application in debug mode.
2.Copy the database file from your application folder to your sd card:
execute:
./adb -d shell "run-as com.yourpackge.name cat
/data/data/com.yourpackge.name/databases/filename.sqlite >
/sdcard/filename.sqlite"
Pull the database files to your machine: execute:
./adb pull /sdcard/ execute: ./adb
Install Firefox SQLLite Manager:
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
5.Open Firefox SQLLite Manager and open your database file from step 3
above.
Where can I find my database file ? The data file shows empty although I have rooted my device. I'm sorry if this is a silly question but I really do not know how to access SQLite using real device.
Some said that database can be accessed once the device is rooted but not works for me. How do I view the SQLite database on an Android device?
you can user Root Explore,before this,you must root your device and user root permission to run the app ,then open and find data folder and open the folder then continue find data folder and open ,you will find the app files in this device,find your packagename and you can find the db,you can use copy the db to sdcard

View SQLite DB on Android device

ALL,
I have an Eclipse Kepler where I am developing my Android application. This application uses SQLite for data persistence.
What I'd like to do is to see the database/tables/data inside Eclipse.Following this I opened installed the plugin, then opened File Explorer.
Problem is: trying to open /data is unsuccessful. It does not open.
Do I have to root the device to open this directory? I have LG phone with Android 2.2.
Permission sets for this folder is drwxrwx--x.
Thank you.
[EDIT]
I also tried to run the shell
igor#IgorReinCloud ~ $ android_sdk/platform-tools/adb -d shell
$ sqlite3 /data/data/com.radar.radar/databases/friends.db
sqlite3: permission denied
$
So it actually means that this is a permission issue and therefor I will not be able to see the db.
[/EDIT]
you can try
$ adb -d shell
$ run-as [your-package-name]
This should allow you to run commands as the user for that package. No guarantees though. Also, I've found that not all devices appear to have sqlite3 available through the shell.
Another possibility is to do the run-as command as above, then copy the database file to /sdcard, whcih is public. Then you can do adb pull /sdcard/[database-file]. Then you'll have the file on your local machine and can use sqlite3 there.
Using this simple library you can directly view your SQLlite datbase from your app . no need to extra .db file
https://github.com/sanathp/DatabaseManager_For_Android
Its a single java activity file ,just add the java file to your source folder you can view the tables in your app database , update ,delete, insert rows to you table .Everything from your app.
When the development is done remove the java file from your src folder thats it .
It helped me a lot .Hope it helps you too .
You can view the 1 minute demo here : http://youtu.be/P5vpaGoBlBY

Getting SQLite database from emulator (data/data/package_name/databases) to local drive

I would like to edit my app's DB using the SQLite Browser. I'm able to edit the DB using the adb shell (sqlite3), but I would rather edit it using a GUI rather than a command line. How do I get the DB from the emulator to a local drive? As of now I've tried:
1) using the adb pull command to pull the database from the emulator to my local drive.
adb pull data/data/com.myapps.quiz c:/
This command executes correctly, but I'm not able to find the file or directory in the local drive I specified.
2) Used the DDMS Perspective to locate the file in the File Explorer, but every time I get into the data/data directory, I only see directories called "con". I even tried pulling the entire data/data directory, but I can't find the name of the package (com.myapps.quiz) where the database is stored.
What am I missing here? Any help you could provide would be most helpful!
Your database is secure to your package so you cannot get this directly.
I have a work around for this.
What I do is go to shell and run-as my package and copy the database to sdcard using cat
adb shell
run-as your.package.name
cd databases
cat your_database.db > /mnt/sdcard/your_database.db
And I pull the file from the sdcard using File Explorer
Are you sure you're connecting to the emulator instance in DDMS, and not an actual device? I have always been able to push and pull sqlite databases from the
data/data/com.my.package/databases/mydb.sqlite
directory, and I can't think of any setting that would override that. An alternative would be to root an actual phone and then you will be able to move anything from the phone to your computer.

Android SQLite database

I have an application on Android, which uses database (SQLite). And I want to see tables and values in this database. I use Eclipse and I have ADT installed. So I can easily run my apps on emulator. Anyway, it would be great to have some tool or a program? How can I actually see what is in db files? And how to find them? Thanks.
One way is by opening a shell to the emulator and then working with your database through the built in sqlite3 tool.
Example: Assume your app name is "com.example.myapp" and your database name is "mydb"
>adb -e shell
>cd data/data/com.example.myapp/databases
>sqlite3 mydb
at this point you should have a shell to work with your db.
Some useful commands:
.dump
.help
.schema
.exit
If you have a table called "my_table", you can use the select syntax to query.
select * from my_table;
Also, here's a link with more infO: http://developer.android.com/guide/developing/tools/adb.html#sqlite
If you're in the emulator, you can use adb pull command at a command prompt and then load the sqlite file in a sqlite viewer. I've used one that is a Firefox plugin and it worked great.
http://developer.android.com/guide/developing/tools/adb.html#copyfiles
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
Note that this doesn't work when you deploy to an actual device...
adb pull only works with the emulator. You can get right to the db files on a rooted device as well.
The actualy db file will be a .sqlite file at the following location on the emulator:
data > data > your-package-name > databases > your-database-file.

Categories

Resources