简体   繁体   English

从文件夹客观打开数据库

[英]objective-c open database from a folder

I have an app that contains top level folder with subfolders in the app's package - not the Documents area. 我有一个包含顶层文件夹的应用程序,该文件夹的子文件夹位于应用程序的包中,而不是“文档”区域。

Here's the structure: 结构如下:

Document/  
Library/  
appPackage  
/tmp

The folder is visible when you right-click the and select "show package contents". 右键单击并选择“显示包内容”,该文件夹可见。

The subfolder is in the appPackage and visible at this point. 子文件夹位于appPackage中,此时可见。 The subfolder in turn contains multiple folders each with database files with same name 子文件夹又包含多个文件夹,每个文件夹都具有相同名称的数据库文件

appPackage/mainFolder/subFolder_1/app.sql  
                      subFolder_2/app.sql
                      subFolder_3/app.sql

I'd like to open one of these databases (depending on user's choice). 我想打开这些数据库之一(取决于用户的选择)。 Optimal way would be to open the database from the current location rather than copying it to the Documents area of the app. 最佳方法是从当前位置打开数据库,而不是将其复制到应用程序的“文档”区域。 I am trying to avoid it. 我正在努力避免它。

My question is: How do I tell sqlite3 interface to open the database from one of these paths? 我的问题是:如何告诉sqlite3接口从这些路径之一打开数据库?

BTW, I am able to access a .txt file in these subfolders - but not sure about database. 顺便说一句,我能够访问这些子文件夹中的.txt文件-但不确定数据库。

All help appreciated. 所有帮助表示赞赏。 R/- : Sam R /-:山姆

NSString *myPath = ...;
sqlite3 *db = NULL;
if (SQLITE_OK == sqlite3_open([myPath fileSystemRepresentation], &db) {
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM