Inspecting android sql database from Eclipse - android

Is there a way to directly inspect an SQLite3 database in Android via Eclipse or do I have to do this via the shell?

I don't know if you can inspect it from within eclipse but you can pull a copy of the database file from the DDMS perspective in the file explorer in folder
data->data->your.package.name->databases
which you can inspect with a free database manager such as sqlite studio

Unfortunately AFAIK you always have to use the shell currently. (Well, not quite. You can use DDMS in Eclipse to pull the database, but that's not much better than using the shell).
Basically you can either 1) pull the database file from the emulator / phone and then inspect it, or you can 2) manually run some SQL queries from inside the emulator/phone.
For 1, I would recommend creating a script. Here is simple example
$ cat android_pull_db
#!sh
adb shell "chmod 777 /data/data/com.mypackage/databases/store.db"
adb pull /data/data/com.mypackage/databases/store.db
$
To create your own, paste the lines from #!... down to adb pull ... into a text file, and save it somewhere. Modify the package location and database filename. Make it executable, and add it to your path.
For 2, just execute this:
$ adb shell
$ cd /data/data/com.yourpackage/databases
$ sqlite3 your-db-file.db
> .help

http://sqlitebrowser.sourceforge.net/index.html
This is a simple way of inspecting the contents of a database. Just use the DDMS to pull the database from the device and then open.

https://github.com/cattaka/TelnetSqlite/wiki
I made it this by following 3 step.
Embed a small program
Add code to kick the embedded program in the Application.onCreate() method
Execute the telnet and run SQL via small program
But it is not from Eclipse. It uses telnet or a sql editor named RdbAssistant.

Related

Ionic SQLite database - default location on Android

I have a pretty simple problem, I need to find out where the database file created by Ionic Native SQLite plugin exists by default.
I've tried using Windows search, which resulted in rendering the whole file system inaccessible. A desktop search application I use refused to search the storage of my mobile phone.
I was able to access the database with adb, as explained in this post:
copy db file with adb pull results in 'permission denied' error
So the command was:
adb -d shell "run-as my.package.name cat ./databases/database.db" > database.db

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

Where is the sql Database?

I try to work with SQLite but I don't know what I'm doing wrong.
I've made an example to insert a records and it works but I can't see the database. I'm working with a real device.
I've found (in Internet) that the database should be in:
/data/data/paquete.java.de.la.aplicacion/databases/database
But this folder seems empty. I've tried with oi File Manager application and File Explorer of Eclipse.
On the other hand, I'm sure that the records have been inserted because if I debug, I can see the them in Log Cat.
Any ideas?
Thanks in advance.
As long as the application is built in debug mode there is no need to have the device rooted. Try
adb shell
run-as your.package.name
ls databases
In order to see the database files on a phone or through eclipse, your device needs to be rooted. If you want to test your database to see what it looks like and if it's working otherwise, you can run your app on the emulator and see it just fine.
What is rooting..?!
You need to be rooted to be able to see the database.
With the emulator you have root access and you can use sqlite3 to open the database from within an emulator shell. Use .dump to dump all contents of the database.
So the commands you would have to do:
Open shell on emulator:
adb shell
Within shell:
cd /data/data/paquete.java.de.la.aplicacion/databases/databases
sqlite3 *yourdatabase.db*
Within sqlite3
.dump
Mit .exit geht's wieder raus aus sqlite3.

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