views:

1338

answers:

3

I've read the answer to a question as to how to access the contents of the databases, however I cannot seem to get it to work on my machine. Here is the shell log:

C:\android-sdk-windows\tools>adb -s emulator-5554 shell
# sqlite3 /data/data/com.android.demo.notepad2/databases/notes
sqlite3 /data/data/com.android.demo.notepad2/databases/notes
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
.tables
sqlite> ^C
C:\android-sdk-windows\tools>

SQLite simply echos my commands back to me, even although the Eclipse file browser tells me it exists. If I use the sqlite3 tool and use ".tables" the commands are accepted.

Is the SQLite syntax different through the emulator is am I missing something?

(Sorry for so many questions, there doesn't seem to be much coherent documentation on Anroid!)

Thanks!

+1  A: 

I can tell you that it works fine for me on Android 2.0.1:

$ adb shell
# cd /data/data/apt.tutorial   
# ls
lib
databases
shared_prefs
# cd databases
# ls
lunchlist.db
# sqlite3 lunchlist.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
android_metadata  restaurants     
sqlite> .exit
# exit

You can always download the database file using DDMS or adb pull and use a desktop SQLite client to examine it. For example, I use the SQLite Manager plugin for Firefox.

Also, bear in mind that SQLite has no default file extension, so if your database is not notes but notes.db or notes.sqlite or something, you'll need to specify the extension.

Also also, I have not tried this on Windows, and there's a possibility that there is something goofy with the Windows command prompt and the limited shell available on Android devices that is causing your difficulty.

CommonsWare
A: 

If you want to issue sqlite3 statements from command line use something like

$ adb -e shell sqlite3 -batch /data/data/com.example.dbsample/databases/db '.tables'
android_metadata

$ adb -e shell sqlite3 -batch /data/data/com.example.dbsample/databases/db 'select * from android_metadata;'
en_US

the obvious advantages are that you can rely on your shell history and you can use this in scripts.

dtmilano
A: 

Another interesting twist on my machine, if the database did not have an extension sqlite would not find it. When I changed the db name from from notes to notes.db everything works fine

matt