views:

43

answers:

2
A: 

sqlite3_exec usually returns an error code (int), and the last parameter can be a pointer to a string that will set an error message. What do those say?

sqlite3_exec(database, [sql UTF8String], MyCallback, nil, &errorMsg);
MPelletier
Hi,I just checked the error code and it is returning 8 (SQLITE3_READONLY) which is a starting point for me to now explore. I didn't realise files in the bundle were read-only.Any idea where and how to place the database file in a read-write area?
Iain Hemstock
Also should I have a single instance of the database, say in the app delegate, that all other classes access? Accessing the database using code like above in my original message from different classes would keep creating a new instance of the original database and overwrite any new changes, right?
Iain Hemstock
@Iain Hemstock - You're not required to have single database instance, but it probably makes sense to do that. Typically, you have a single database instance per thread. The database changes will be shared across all database instance objects in your app. It's the way SQLite is designed.
sheepsimulator
I'm no iPhone expert (yet!), so my knowledge is limited here. I can tell you that you would be best to use a single instance, even though acessing it multiple times will not create multiple instances. Have you tried using CoreData?
MPelletier
@sheepsimulator - Ah, good to know. It wasn't a problem run into yet, just hoping to preempt a potential problem!@MPelletier - Since this is the first iPhone project of size I've done I was keeping things relatively simple by using sqlite3 (having used MySQL before, the transition would be simple enough)so have avoided CoreData for this project.I've just read that the database can go into the Documents folder rather than be accessed through the bundle and am about to explore this. Thanks for all the help.
Iain Hemstock
A: 

Ah, right, figured out the process now which may answer someone else's query. Basically I had the database in the resource bundle with some basic data for my tests which I could read fine. But because the bundle resource is read only I couldn't write data back to the database.

So the solution is to copy the database into the app's Documents folder at application startup programatically but with code to see if the database already exists there (in order not to overwrite it). Because this folder is read-write there should be no issue in updating the database.

Iain Hemstock