将 SQLite 数据库添加到 iPhone 应用程序

将 SQLite 数据库添加到 iPhone 应用程序

问题描述:

我正在尝试学习 SQLite,并且正在构建一个 iPhone 应用程序.但我想在我的建筑应用程序中添加一个 SQLite 数据库.我有三个教程,但我不清楚那个代码.

I am trying to learn SQLite, and I am building an iPhone app. But I would like to add an SQLite database to my building app. I have got three tutorials, but I am not clear on that code.

如何将 SQLite 数据库添加到我的构建应用程序中?示例代码是什么样的?

How can I add an SQLite database to my building app? What would sample code look like?

首先你需要创建你的数据库.
从命令行创建您的数据库文件.

First of all you need to create your database.
From the command line create your db file.

sqlite3 mydb.db

然后在数据库中创建表

CREATE TABLE tags (id int(5), name varchar(255), created_at datetime, updated_at datetime);

对数据库中所需的任何表重复此操作.

Repeat that for any tables that you want in your database.

然后你需要在你的项目中包含数据库文件.像添加任何其他现有文件一样,将现有数据库文件添加到您的项目中.

Then you need to include the database file in your project. Add the existing database file to your project as you would any other existing file.

接下来,您必须在框架中链接以与数据库交互.这可以在您当前的 iPhone SDK 文件夹下找到.

Next you will have to link in the framework to interact with the database. This can be found under you current iPhone SDK folder.

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/lib/libsqlite3.0.dylib

最后你必须包含来自

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/include/sqlite3.h

现在应该可以编写代码来从您的 iPhone 应用程序中访问您的 sqlite 数据库.

It should now be possible to write code to access your sqlite database from within your iPhone application.