将一个SQLite数据库添加到iPhone应用程序 [英] Add an SQLite database to an iPhone app

查看:149
本文介绍了将一个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

然后在数据库中创建表格

Then create the tables within your database

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

/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.

这篇关于将一个SQLite数据库添加到iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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