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

查看:31
本文介绍了将 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.

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

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