Read SQLite database from zip file?

Discussion in 'iOS Development' started by lauNchD, Jul 17, 2010.

  1. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    My app works with several zip files (from an arbitrary source) that each contain a lot of image files and a SQLite database to index them and provide metadata, as well as other information not directly related to the images. To read these zip files, I am using libzip along with a custom Cocoa wrapper to simplify things.

    However, the sqlite library doesn't support loading a database from anywhere other than the default filesystem, so I wrote my own VFS (virtual filesystem) that gets created and registered for any zip file I need. I made it read-only for now, so SQLite won't try and put annoying temporary files into the archive, and when I tell the library it should open my database file read-only, it seems to obey.

    Now for the weird part: When I try to open the database (using sqlite3_open_v2()), it doesn't report any errors and I get a valid database handle/pointer. But when I try to compile a SQL statement, it suddenly throws the SQLITE_NOTADB error, suddenly claiming my file is not a valid database. When I take the database out of the zip file and access it "normally," everything works as expected.

    Some things to clarify:
    • I know this whole thing is overly complicated

      Please Register or Log in to view images

      , but I can't think of any other way to do it.
    • Pulling the database out of the zip file on every app launch is unfeasible for various reasons.
    • I'm using SQLite (as opposed to Core Data) for cross-platform interoperability. A moderate PHP-enabled server should be able to generate the archive.

    I hope anyone of you could help me here. I may give out the source code, but I was wondering if you have any general recommendations when programming these kinds of things.

    Thanks in advance,
    lauNchD

Share This Page