在 Android Studio 中查看设备上的 SQLite 数据库 [英] View SQLite database on device in Android Studio

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

问题描述

我使用的是最新版本的 Android Studio.当我在模拟器上运行我的应用程序时,我可以通过以下方式查看我的数据库:

<代码>工具 ->Android 设备监视器 ->单击左侧面板中的模拟器 ->文件浏览器 ->数据 ->数据 ->com.project-name

但是在设备上运行我的应用程序时,此选项不可用.

我检查了相关问题:

  1. Android - 在设备上查看 SQLite 数据库?这里是投票最多的答案建议将数据库复制到 SDcard 中,它甚至用于 Eclipse.
  2. 在安卓设备上访问 sqlite 数据库

这些问题来自 2011 年和 2010 年.有没有我可以使用的插件或其他外部工具?

解决方案

通过ADB Shell连接Sqlite3

我在 Android Studio 中没有找到任何方法可以做到这一点,但我使用远程 shell 访问数据库,而不是每次都拉取文件.

在此处查找所有信息:http://developer.android.com/tools/help/adb.html#sqlite

1- 在命令提示符中转到您的平台工具文件夹

2- 输入命令 adb devices 以获取您的设备列表

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb devices连接的设备列表模拟器-xxxx 设备

3- 将外壳连接到您的设备:

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s emulator-xxxx shell

4- 导航到包含您的 db 文件的文件夹:

cd data/data//databases/

5- 运行 sqlite3 连接到您的数据库:

sqlite3 .db

6- 运行您喜欢的 sqlite3 命令,例如:

Select * from table1 where ...;

<块引用>

注意:在下面找到更多要运行的命令.

SQLite 备忘单

查看 SQLite 数据库中的表有几个步骤:

  1. 列出数据库中的表:

    .tables

  2. 列出表格的外观:

    .schema 表名

  3. 打印整个表格:

    SELECT * FROM tablename;

  4. 列出所有可用的 SQLite 提示命令:

    .help

来源:这个所以答案..

I am using the latest version of Android Studio. When I run my app on the emulator, I am able to view my database by going through:

tools -> Android Device Monitor -> clicking on the emulator in the left panel -> file explorer -> data -> data -> com.project-name

But this option isn't available when running my app on a device.

I have checked related questions:

  1. Android - viewing SQLite databases on device? The most voted answer here suggests copying the database to SDcard, and it's even for eclipse.
  2. Access sqlite database on android device

and these questions are from 2011 and 2010. Are there any plugins I can use or other external tools?

解决方案

Connect to Sqlite3 via ADB Shell

I haven't found any way to do that in Android Studio, but I access the db with a remote shell instead of pulling the file each time.

Find all info here: http://developer.android.com/tools/help/adb.html#sqlite

1- Go to your platform-tools folder in a command prompt

2- Enter the command adb devices to get the list of your devices

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb devices
List of devices attached
emulator-xxxx   device

3- Connect a shell to your device:

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s emulator-xxxx shell

4- Navigate to the folder containing your db file:

cd data/data/<your-package-name>/databases/

5- run sqlite3 to connect to your db:

sqlite3 <your-db-name>.db

6- run sqlite3 commands that you like eg:

Select * from table1 where ...;

Note: Find more commands to run below.

SQLite cheatsheet

There are a few steps to see the tables in an SQLite database:

  1. List the tables in your database:

    .tables
    

  2. List how the table looks:

    .schema tablename
    

  3. Print the entire table:

    SELECT * FROM tablename;
    

  4. List all of the available SQLite prompt commands:

    .help
    

Source : This SO answer..

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

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