Have you ever seen the following error message:
Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0x3baae90 "Operation could not be completed. (Cocoa error 256.)
Talk about not Helpful.
Inside this there was a userInfo dictionary with the following message:
error during SQL execution : constraint failed
Slightly more helpful, but not by very much.
We came across this error message while we were developing our Electrophobe game. We started the debugging process by inserting logging code and pinpointing where the code was failing out. After about 6 hours of work combing through both code and rebuilt databases we finally found the solution.
The trick was that the primary key store for the SQLite3 database that was backing our CoreData NSPersistenceStore had an incorrect value for the Z_MAX column. This column is used, we believe, to house the maximum primary key in order to quickly retrieve it for additional inserts.
As is evident from our escapade however, it is clearly a little vulnerable to tampering when loading the data directly into the SQLite database. To fix the issue, simply update the table with the max(Z_ID) from the referenced table and it should all hook up again.
Tags: Cocoa, CoreData, Error 256, NSPersistenceStore, SQLite, Troubleshooting
Comments
I can’t even fathom how long it would have taken me to solve this without your blog post.
Thank you so much.
Guys thanks a lot.
You have just saved me hours of debugging.
Same problem here, nice to see someone else is in the same boat as me,but how do you “simply update the table with the max(Z_ID) from the referenced table and it should all hook up again.”?
Thanks
Use the sqlite3 program from the command line to access the database file and run an update statement to set the maximum ID. You will then have to repackage it for your distribution.
That’s not he problem, how do yo push the updates to the user’s database?
Generally this problem happens when you are compiling the initial push of data out to applications. If you had this problem before you pushed your application out then you would not be able to retrieve information from your database.
The CoreData classes manage this just fine if you have not tried to circumvent the CoreData methods of doing this. If you did manage to get this to be broken and you need to push an update into client applications that are already deployed out to end users phones then you are going to have to use the sqlite3 libraries that are on the phone (which are C based) to execute the appropriate SQL queries on the phone as part of an upgrade process.
Documentation for sqlite can be found here: http://sqlite.org/
If you want to look at some info about deploying read-write resources then you can look here: http://blog.beefyapps.com/2009/10/deploying-a-readwrite-resources-with-your-iphone-application/
Moving beyond the second link really involves coming up with some sort of versioning token that can be kept around. I suggest using a version table in the database and then building up from there.
[...] I got an error exactly same as this post described. [...]
[...] searching the web, I found this article that talks about that very message, but it doesn’t seem to apply as apparently the [...]
Post a Comment