XCode Not Copying Database

Posted on 2009-12-18
Last Modified: 2013-11-25
I've got an iPhone app that uses a SQLite database.  USED to work, until I built for distribution.  Now it's not working anymore.  It can FIND the database, and it can OPEN it, but can't READ from it.


1)  I added the database as an "existing file" to the resources directory of my project.
2)  I checked the checkbox "Copy this file's contents" in the popup when you add a file.
3)  I double-checked the original database before I copied it into the resource directory... 31M.
4)  I build the project.
5)  I checked the application directory for the build, and found that a file had been created that was the same name as my database file, but it was empty...  zero K in size.  No contents.
6)  When I ran the application, it found the database, and did an OPEN successfully... but when I tried to execute a "sqlite3_prepare_v2" statement, it returned a SQLITE_ERROR, which indicates that it can't read/find the database.

Any ideas?
Question by:eDistrict
    LVL 9

    Expert Comment

    Hi there,

    You can try to delete it and then add it again to the resource folder, if you haven't tried it yet. As for trying to use the database, I had to make a copy of the database to the documents folder the first time the application ran on an iPhone.

    Here is a link that will explain it better than I can:

    Hope it helps ^_^

    Accepted Solution

    The actual solution was much simpler... apparently, XCode has a bug that keeps it from copying the contents of a sqlite file if the file extension is anything other than .sql.   My database had a .db extension, and XCode was creating a file of 0k with that name, but was not copying over the contents.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Creating and Managing Databases with phpMyAdmin in cPanel.
    The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now