在设备上调试SQLite数据库 [英] Debugging sqlite database on the device

查看:118
本文介绍了在设备上调试SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是presently正在为Android的无线应用。我有麻烦试图访问数据库中的设备上。在调试仿真器不适合我,因为在模拟器无WiFi的支持。我试图用拉数据库文件从设备中

I am presently working on an WiFi application for Android. I am having trouble trying to access the database on the device. Debugging in the emulator doesn't work for me, because there is no WiFi support in the emulator. I tried pulling the database file out of the device by using

adb pull data/data/package-name/databases/database-name

不过,我得到错误权限被拒绝。 在这种应答<一个href="http://stackoverflow.com/questions/1105219/android-where-are-database-files-stored/1106563#1106563">Android:在哪里存储数据库文件?,Commonsware曾建议在调试模式下运行拉数据库文件。但它不工作了。如何在数据库中没有生根的设备将大大AP preciated调试任何帮助。

But I get the error "Permission denied.". In this answer Android: Where are database files stored?, Commonsware has suggested to pull database file by running in debug mode. But it doesn't work too. Any help on how to debug the database without rooting the device would be much appreciated.

推荐答案

我会重复自己从另一个答案

从API级别8(安卓2.2)开始,如果您构建应用程序的可调试,您可以使用命令行运行方式命令来运行一个命令或可执行文件特定用户/应用程序或只是切换到 UID你的应用程序这样你就可以访问其数据目录。

Starting from API level 8 (Android 2.2), if you build the application as debuggable, you can use the shell run-as command to run a command or executable as a specific user/application or just switch to the UID of your application so you can access its data directory.

所以,如果你想从设备拉你的应用程序数据库,您应该运行在调试模式下的应用程序(这样做,只是从Eclipse运行),跟 ADB -d壳并运行以下命令:

So if you wish to pull your application database from the device you should run the application in the debug mode (to do so, simply run it from the Eclipse), connect with adb -d shell and run the following commands:

run-as package-name
cat /data/data/package-name/databases/database-name >/sdcard/database-name

这将复制 yourdatabase.db 到SD卡的根目录。现在,你可以很容易地把它从那里(通过使用USB存储,亚行拉的,或者你喜欢的任何其他)。
&NBSP;
更新 @Shiki提供了一个便捷的内胆可以用没有进入亚行的shell:

This will copy yourdatabase.db to the root of your SD card. Now you can easily get it from there (by using USB storage, adb pull or whatever else you like).
 
UPDATE @Shiki provided a convenient one-liner one can use without entering the adb shell:

亚行-d壳运行方式com.yourpackage猫/data/data/com.yourpackage/databases/dbname.sqlite&GT; /sdcard/dbname.sqlite

这篇关于在设备上调试SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆