如何让 Xcode Iphone Simulator 将 SQLite 数据库保存到本地文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12785374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:44:32  来源:igfitidea点击:

How to make Xcode Iphone Simulator save SQLite database to local file?

iosxcodecordovaios-simulator

提问by Kenci

I am building my first iPhone app with CSS, HTML, Javascript and PhoneGap. I want to use SQLite as the database, so i am using the following tutorial as inspiration:

我正在用 CSS、HTML、Javascript 和 PhoneGap 构建我的第一个 iPhone 应用程序。我想使用 SQLite 作为数据库,所以我使用以下教程作为灵感:

http://coenraets.org/blog/2011/10/sample-app-using-the-phonegap-database-api/

http://coenraets.org/blog/2011/10/sample-app-using-the-phonegap-database-api/

The following code determines weather to use data from the database, or to populate the database with data first:

以下代码确定天气是使用数据库中的数据,还是先使用数据填充数据库:

function onDeviceReady() {

    db = window.openDatabase("EmployeeDirectoryDB", "1.0", "PhoneGap Demo", 200000);
    if (dbCreated)
        db.transaction(getEmployees, transaction_error);
    else
        db.transaction(populateDB, transaction_error, populateDB_success);
}

After debugging, i found out that every time i run the app, it populates the database, so

调试后,我发现每次运行应用程序时,它都会填充数据库,所以

if (dbCreated)

never executes.

从不执行。

I want to have a look at the SQLlite file, so i am using SQLite Database Browser to locate it, without luck. From the following question:

我想看看 SQLlite 文件,所以我使用 SQLite 数据库浏览器来定位它,但没有运气。从以下问题:

How to view the data in sqlite file running in iphone application?

如何查看在 iphone 应用程序中运行的 sqlite 文件中的数据?

I can see that the file should be located somewhere in this folder:

我可以看到该文件应该位于此文件夹中的某个位置:

user/Library/Application Support/iPhone Simulator/

But the iPhone Simulatorfolder does not exist.

但是iPhone Simulator文件夹不存在。

How do i make the simulator save the database to a local file?

如何让模拟器将数据库保存到本地文件?

采纳答案by alexandresoli

Each time you run your application on simulator, it creates a folder inside iphone simulator folder .Make sure your Library folder is visible and you are using the correct path.

每次在模拟器上运行应用程序时,它都会在 iphone 模拟器文件夹中创建一个文件夹。确保您的库文件夹可见并且您使用的是正确的路径。

To make library folder visible you can run the following command on terminal:

要使库文件夹可见,您可以在终端上运行以下命令:

chflags nohidden ~/Library

chflags nohidden ~/Library

Here`s the path for my iphone simulator folder to use as a reference:

这是我的 iphone 模拟器文件夹的路径,用作参考:

/Users/alexandreoliveira/Library/Application Support/iPhone Simulator

/用户/alexandreoliveira/图书馆/应用程序支持/iPhone模拟器

Another thing to notice, usually the sqlite database get saved inside documents folders:

另一件要注意的事情,通常 SQLite 数据库保存在文档文件夹中:

Users/alexandreoliveira/Library/Application Support/iPhone Simulator/5.1/Applications/some-weird-numbers/Documents/

用户/alexandreoliveira/Library/Application Support/iPhone Simulator/5.1/Applications/some-weird-numbers/Documents/