views:

98

answers:

2

Hi, Everyone: 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 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!

+3  A: 

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.

Colin Gislason
Yes, that's true. Why i did not find that. Thanks!
Elliot Chen
Since i'm new here, has no GEMs to give your answer a vote. So, only thanks!
Elliot Chen
Hi, I just know how to accept answer. Sorry for a delay and thanks again!
Elliot Chen
No problem, I'm glad I could help.
Colin Gislason
+1  A: 

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?

Sixten Otto
Thanks for your info, I did not know that Document folder can be read by other app on iPad. I'll try to put it at application folder.
Elliot Chen
Not other applications on the device, mind you. Apps are still sandboxed. But the user can manage the documents from their PC with iTunes. And there may be other ways in the future. Basically, it's safer to think of that folder being under the user's control, as it is on the Mac.
Sixten Otto