开发者

What is the proper location for a sqlite3 database file?

开发者 https://www.devze.com 2022-12-29 12:34 出处:网络
I\'m using a sqlite3 database to store app\'s data. Instead of building a database within program, I introduced an existing db file: \'abc.sqlite\' into my project and put it under my \'Resources\' fo

I'm using a sqlite3 database to store app's data. Instead of building a database within program, I introduced an existing db file: 'abc.sqlite' into my project and put it under my 'Resources' folder. So, I think this db file should be inside of 'bundle', so at my init function, I used following statement to read it out:

NSString *path = [[NSBundle mainBundle] pathForResource:@"abc" ofType:"sqlite"];
if(sqlite3_open([path UTF8String], &database) != SQLITE_OK)
...

It's ok that this db can be opened and data can be retrieved from it. BUT, someone told me that it's better to copy this db file 开发者_C百科into user folder: such as 'Document'. So, my question is: is it ok to use this db from main bundle directly or copy it to user folder then use that copy. Which is better?

Thank you very much!


You should use it from your bundle if you only require readonly access. If you need to write to the file, you need to move it somewhere writable like the documents directory.

Also, as Sixten Otto notes, the Application Support directory is preferable to the Documents directory in newer SDKs.


Given that the contents of the Documents folder will probably be visible to users using the file-management features on iPad, and in newer versions of the iPhone OS, may I suggest the Application Support folder?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号