开发者

adb unable to show / open / connect database

开发者 https://www.devze.com 2023-03-09 04:50 出处:网络
I try to use adb to query my sqlite3 db. I use this db with my app on emulator without any problems, but I\'m not able to query it from the adb shell. I have read a lot here and on Android developer g

I try to use adb to query my sqlite3 db. I use this db with my app on emulator without any problems, but I'm not able to query it from the adb shell. I have read a lot here and on Android developer guide to understand my problem/error but I have not solved anything.

Here's a trace of what happens when I try to query the database from adb:

adb -s emulator-5554 shell

sqlite3 /data/data/rf.stats/databases/sstatsdb.db

SQLite version 3.5.9

Enter ".help" for instructions

sqlite> .tables

sqlite> select * from games;

SQL error: no such table: games

sqlite> .databases

seq name file

--- --------------- ----------------------------------------------------------

0 main /data/data/rf.stats/databases/sstatsdb.db

1 temp /sqlite_开发者_JAVA技巧stmt_journals/etilqs_H2EoeecYlb1UK2U

Why can't I query my database from the adb shell, given that it works in the emulator?

I'm on Ububtu Lucid with Android 10.0.1 and Java SDK 6.


adb doesn't have permission to look inside /data on the phone. The emulator doesn't have this restriction. It's part of the security model that prevents people from accessing data belonging to third-party applications.

There are two ways to get around this:

  • the official way is to set your application as debuggable (by putting android:debuggable="true" in the <application> element in the manifest), and then use DDMS; however, I've never managed to make this work.

  • the unofficial but much more useful way is to jailbreak the phone using something like SuperOneClick. This will let you log in as root with adb, which will then give you full access to all data on the phone (including your application's).


This works for me on Windows, it should work for you on Ubuntu as well. Navigate to platform tools directory first:

> cd C:\Users\[Your Username]\android-sdks\platform-tools
> adb shell
> cd data/data/[application namespace]/databases/
# sqlite3 [Database Name].db
sqlite> select * from [Table Name];

Replace what's between brackets "[" ... "]" with yours and it should work. The trick is once you are inside the adb shell to navigate to the databases directory that belongs to your specific application, then run sqlite3 to query. Otherwise sqlite3 won't be looking in the correct location.

Pete


I would advice to check if the table you ask about really exists in this databases because

sqlite> .tables

should return all the tables created in the /data/data/rf.stats/databases/sstatsdb.db database. Here is an example output of populated DB:

sqlite3 webview.db
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
.tables
android_metadata  formdata          httpauth
cookies           formurl           password


I encountered this problem. Type sqlite3 /data/data/rf.stats/databases/sstatsdb with out the .db.

Hope it solves your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消