adb 无法显示/打开/连接数据库

发布于 2024-11-10 18:45:35 字数 757 浏览 7 评论 0原文

我尝试使用 adb 查询我的 sqlite3 数据库。我在模拟器上将这个数据库与我的应用程序一起使用,没有任何问题,但我无法从 adb shell 查询它。我在这里和 Android 开发人员指南上阅读了很多内容以了解我的问题/错误,但我还没有解决任何问题。

以下是我尝试从 adb 查询数据库时发生的情况:

adb -s emulator-5554 shell
sqlite3 /data/data/rf.stats/databases/sstatsdb.db
SQLite版本3.5.9
输入“.help”以获取说明
sqlite> .tables
sqlite>从游戏中选择*;
SQL 错误:没有这样的表:games
sqlite> .数据库
seq 名称文件
--- --------------- -------------------------------- --------------------------------------
0 主要/data/data/rf.stats/databases/sstatsdb.db
1 临时 /sqlite_stmt_journals/etilqs_H2EoeecYlb1UK2U

鉴于它可以在模拟器中运行,为什么我无法从 adb shell 查询我的数据库?

我使用的是带有 Android 10.0.1 和 Java SDK 6 的 Ububtu Lucid。

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_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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

江湖正好 2024-11-17 18:45:35

adb 无权查看手机上的 /data 内部。模拟器没有这个限制。它是安全模型的一部分,可防止人们访问属于第三方应用程序的数据。

有两种方法可以解决此问题:

  • 官方方法是将应用程序设置为可调试(通过将 android:debuggable="true" 放入 清单中的元素),然后使用 DDMS;然而,我从来没有成功地完成这项工作。

  • 非官方但更有用的方法是使用 SuperOneClick 等工具对手机进行越狱。这将允许您使用 adb 以 root 身份登录,然后您将能够完全访问手机上的所有数据(包括您的应用程序的数据)。

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).

木落 2024-11-17 18:45:35

这在 Windows 上适用于我,在 Ubuntu 上也应该适用于你。首先导航到平台工具目录:

> 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];

将括号“[”...“]”之间的内容替换为您的内容,它应该可以工作。诀窍是,一旦您进入 adb shell,导航到属于您的特定应用程序的数据库目录,然后运行 ​​sqlite3 进行查询。否则 sqlite3 将不会查找正确的位置。

皮特

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

卷耳 2024-11-17 18:45:35

我建议检查您询问的表是否确实存在于该数据库中,因为

sqlite> .tables

应该返回 /data/data/rf.stats/databases/sstatsdb.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 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
最初的梦 2024-11-17 18:45:35

我遇到了这个问题。类型sqlite3 /data/data/rf.stats/databases/sstatsdb
没有.db

希望它能解决您的问题。

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

Hope it solves your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文