is there some way I can view a SQLite db? - android

I'm encountering a very odd behavior where a SQLite db entry is not throwing any exceptions, but when I later do a select where I search for the row I have inserted, it doesn't turn up.
I'm at a loss as to how to debug this, as I have no way to verify that the insert is actually working. I've examined all the SQL calls and they look right, so now I'm just stuck.
Is there a phone resident db tool of some sort that I can use to view the db? Or an ADB command line SQL thing of some sort?

Yes. ADB will let you examine databases from the shell.
See this page on the Android site: http://developer.android.com/guide/developing/tools/adb.html#sqlite

If you want this for development - you can use MOTODEV Studio from Motorola It has UI for SQlite. Its free!

Pull out the db file from the emulator. Open it with SQLite Browser.
And there are adb commands:
$ adb -s emulator-5554 shell
# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions
.... enter commands, then quit...
sqlite> .exit

Related

SQLite3 doesn't show anything

I am learning from the book: "Learning Android" (Marko Gargenta - O'REILLY) I am in chapter 9 (The Database).
I am trying to show anything useful using sqlite3. I opened the emulator. I opened the File Explorer in eclipse, I found that I have a database in my emulator which has the path
data/data/saleh.yamba/databases/timeline.db
data/data/saleh.yamba/databases/timeline.db-journal
I followed the book instructions to open the database in sqlite3
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
sqlite> adb shell
...> ls /data/data/saleh.yamba/databases/timeline.db
...> cd /data/data/saleh.yamba/databases/
...> sqlite3 timeline.db
...> SELECT * FROM timeline;
Error: near "adb":syntax error
sqlite>
.....
For example; after ls /data/data/saleh.yamba/databases/timeline.db I expected to list something, but what happens is that it just jumps to the next line printing ...>
So I can't get anything useful, what is the wrong? How to fix it?
Thank You.
adb shell is not a SQLite command.
I guess what your are trying to do is:
$ adb shell sqlite3 /data/data/saleh.yamba/databases/timeline.db
to start sqlite3 and open the database
You can't select directly from the db - you would need to select from a table inside the db.
As you most likely don't know the insides of this db try creating one on your own, I guess that shouldn't be much further in your book.
just go with this post.
http://developer.android.com/tools/help/sqlite3.html
and try to follow same commands.with correct syntax.

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.

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.

How to fetch call log details from an android emulator?

Can anyone please tell me how to fetch call log details from android emulator?
where does this type of data reside on phone?
waiting for answers. :)
thanks.
Try this command:
adb shell
#cd /data/data/com.android.providers.contacts/databases
# sqlite3 contacts2.db
SQLite version 3.5.0
Enter ".help" for instructions
sqlite> select * from calls;
You can fetch all call log details from android emulator .
The call log data is co-located in the contacts db.
Here's the blog post where the following code snippet came from:
http://mylifewithandroid.blogspot.com/2008/01/phonecalls.html
adb shell
#cd /data/data/com.google.android.providers.contacts/databases
# sqlite3 contacts.db
SQLite version 3.5.0
Enter ".help" for instructions
sqlite> .dump
As you can see, the post is from 2008, so things might have changed since then. Your best bet is to peruse the developer reference on [developer android com]
got the answer..its using content provider only.
foll the link:
http://www.anddev.org/images/tut/basic/calllog_displayer/screencast.htm

Inspecting android sql database from Eclipse

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.

Categories

Resources