iPhone在运行时创建SQLite数据库? [英] iPhone create SQLite database at runtime?

查看:95
本文介绍了iPhone在运行时创建SQLite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数sqlite示例我已经发现谈论从命令行创建一个数据库文件,然后将它添加到您的应用程序。对于我的项目,我希望能够在应用程序中首次启动时创建我的数据库,然后将其保存到用户沙盒中的db文件。有办法吗?

Most sqlite examples I've found talk about creating a db file from the commandline first and then adding that to your app. For my project, I'd like to be able to create my database within the app when it starts up for the first time and then save it to a db file in the user's sandbox. Is there a way to do that?

推荐答案

应用程序启动时可以检查文件如果文件不存在,而不是复制预创建的文件,只需:

You can check for the file (as usual) when the application starts up. If the file does not exist, instead of copying the pre-created file, simply:


  1. 像往常一样使用 sqlite3_open()

  2. 运行创建命令(即创建表,视图等)

这真的是所有的。

这篇关于iPhone在运行时创建SQLite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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