从android拉取Sqlite数据库给出空数据库 [英] Pulling Sqlite database from android gives empty database

查看:69
本文介绍了从android拉取Sqlite数据库给出空数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 Sqlite 的移动应用程序,我想从手机中提取 .db 文件并在 Sqlite 的数据库浏览器中查看它.

I am developing a mobile application that uses Sqlite and I would like to pull the .db file from the phone and view it in DB Browser for Sqlite.

问题来自这样一个事实,即当我运行 adb 命令时,我得到的 .db 文件是空的,即使我已经创建了表并将数据添加到数据库中的这些表中.

The issue comes from the fact that when I run the adb commands the .db file I get is empty, even though I have creatd tables and added data to those tables in the database.

在应用程序中,我查询数据库中插入的记录并返回它们.有什么想法吗?

In the application I query the database for the inserted records and they are returned. Any thoughts?

adb 命令:adb exec-out run-as projectname cat databases/my.db >my.db

数据库创建代码:

if(!Sqlite.exists("my.db")){
        new Sqlite("my.db")
        .then(
            (db) => {
            //create table here
                db.execSQL("CREATE TABLE IF NOT EXISTS Times (Id INTEGER PRIMARY KEY AUTOINCREMENT, clockIn TEXT, clockOut TEXT)")
                .then(
                    () => {
                        console.log("succcess")
                        db.execSQL("INSERT INTO Times (clockIn, clockOut) VALUES (?, ?)", ["Nic", "Raboy"]).then(() => {
                            db.all("SELECT * FROM Times").then((rows) => {
                                console.log(rows)
                            })
                        })

                    }, 
                    (error) => { 
                        console.log('Error occurred creating table');
                    });
        },
            (error) => {
                console.log("Error creating Database");
            });
    }    

推荐答案

我想出了如何解决这个问题.在 android 9 上,使用 adb 拉取时必须包含 -wal 和 -shm 文件.然后当 .db 文件打开时,您将看到您构建的数据库,而不是一个空的骨架 db.

I figured out how to solve this issue. On android 9 you have to include the -wal and -shm files when pulling using adb. Then when the .db file is opened you will see your database as you have built it and not an empty skeleton db.

这可能不是最好的方法,但它会起作用:

This may not be the best way of doing this but it will work:

adb exec-out run-as projectname cat databases/my.db > my.db
adb exec-out run-as projectname cat databases/my.db-shm > my.db-shm
adb exec-out run-as projectname cat databases/my.db-wal > my.db-wal

这篇关于从android拉取Sqlite数据库给出空数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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