Android:使用sqlte-browser打开时,使用空间创建的SQLite数据库未显示任何表 [英] Android: SQLite database created with room shows no tables when opening with sqlte-browser

查看:164
本文介绍了Android:使用sqlte-browser打开时,使用空间创建的SQLite数据库未显示任何表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Room Persistence Library 1.1.0 .我可以使用Android Studio的设备文件资源管理器在/data/data/<package_name>/databases/处找到数据库文件.它包含多个表,使用room-DAO s可以毫无问题地访问这些表的内容.但是,使用sqlite-browser打开时,没有显示表格.

I am using Room Persistence Library 1.1.0. I could find the database file at /data/data/<package_name>/databases/ using Android Studio's Device File Explorer. It contains multiple tables and I can access contents of that tables without any problem using room-DAOs. However when opening with sqlite-browser, is shows no table.

可能是什么原因?是否可以解决问题而无需从房间切换回旧的SQLiteOpenHelper?

What might be the reason? Is it possible to resolve the issue without switching back to old SQLiteOpenHelper from room?

推荐答案

解决方案

要使用sqlite-browser打开此类数据库 *,您需要复制所有三个文件.所有都必须在同一个目录中.

Solution

To open such databases* with sqlite-browser, you need to copy all three files. All must be in the same directory.

*如问题所述,数据库存储在多个文件中.


根据文档,从版本1.1.0开始,Room使用write-ahead logging作为具有足够RAM且在API级别16或更高版本上运行的设备的默认日记模式.在此版本之前,所有设备的版本均为Truncate.与Truncate相比,write-ahead logging具有不同的内部结构.

As per docs, Starting from version 1.1.0, Room uses write-ahead logging as default journal mode for devices which has sufficient RAM and running on API Level 16 or higher. It was Truncate for all devices until this version. write-ahead logging has different internal structure compared to Truncate.


不时查看SQLite使用的文件临时文件:

Take a look at the files temporary files used by SQLite now and then :

直到1.1.0版

从1.1.0版开始


如果要将日记模式显式更改为Truncate,可以采用这种方式.但是,不推荐,因为与Truncate相比,WAL要好得多.

If you want to change the journal mode explicitly to Truncate, you can do it this way. But, it is not recommended because WAL is much better compared to Truncate.

public static void initialize(Context context) {
    sAppDatabase = Room.databaseBuilder(
            context,
            AppDatabase.class,
            DATABASE_NAME)
        .setJournalMode(JournalMode.TRUNCATE).build();
}


是的.针对数据库查询以下语句.

Yes, it is. Query the following statement against the database.

pragma wal_checkpoint(full)

此处此处进行了详细讨论.

这篇关于Android:使用sqlte-browser打开时,使用空间创建的SQLite数据库未显示任何表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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