xCode Sqlite Database Creation Without Z_METADATA xCode Sqlite Database Creation Without Z_METADATA sqlite sqlite

xCode Sqlite Database Creation Without Z_METADATA


Please start with this basic sanity check: Bring the database to your Mac, open it with sqlite3.exe, and see if the table is present.

If it is, then your program is pointing to the wrong database.If it is not, then your table was never created (or the database is corrupt as hell, but that would be surprising).


Core Data seems to look for the metadata first when it opens a store so a complaint about the Z_METADATA usually indicates a corrupted file or a file in the wrong format. I would suspect either a problem with the copied file (permission, corruption etc) or a problem with the options for the store.

I would suggest:

  1. Open the store as readonly in the app bundle i.e. without copying it and see if it opens fine. If it does, then the problem is in the copying.
  2. Provide an error to the copy method and log its return. The copy might be subtly failing.
  3. Get the size of the copied file. The file might end up in the directory but empty.
  4. Pass a nil options dict to make sure that is not the problem.


First, you need to catch these errors and at least report them:

[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];

Also, that method returns a BOOL of success or failure, you should be watching for that as well.

Beyond that, assuming the sqlite file is valid, there is nothing overtly wrong with the code. Can you duplicate this in a sample application? If so, you can post a link to it in your question and I will be happy to tinker around with it. If it turns out to be an Apple bug you will then have the test case ready for your radar. If it doesn't duplicate in a test then you can compare the differences to see what is wrong in the original application.