I recently ran into an annoying problem getting data from an SQLite database in my iPhone application. I had bundled the database with the application and duplicated code from Apple’s example code. No matter what I did every time I tried to select from my table I would get “no such table: table_name”. I tried checking what tables existed in the database using “SELECT name FROM sqlite_master WHERE type = ‘table'”, and found there were none.
What happened is sqlite3_open() will create a new database if it can’t find the one you requested. It will also cache this empty database and use it in the simulator. So even though I had fixed the issue with my code, that empty database was still being used. The solution to this is to delete the app from the simulator (click and hold the app icon, then click the x) and re-build. This will clear the cached database and use the copy bundled with your app.
Hopefully this will help someone else avoid a few hours of annoyance. It seems to be a fairly common pitfall, but I wasn’t able to find much in the way of answers.
I did everything clear, uninstall, reset simulator.. but still getting same error. It creates EMPTY DB before the sqlite3_open() statement..and I am surprised with that. Any Clue..??
Never mind…I found the problem..Thanks.
same problem,
did all the things,
deleted app from simulator, cleaned all the targets, deleted reference , made newer reference .. then also m facing the same thing,
in this case it got suddenly stopped .
i havent updated DB schema..
@abc If you delete the app from the simulator that should remove any databases. Then make sure that your database is bundled with your app and then you’re opening that database without any typos like I did.
You can always run “SELECT name FROM sqlite_master WHERE type = ‘table’” and check if there is anything in your database. If not either your bundled DB is empty, the OS is caching an empty version, or you’re not selecting the right DB name.
Thanks a lot!! Your answer helped me fix this problem in like a matter of minutes(spent only an hour on this problem) and yea, there aren’t much answers about this problem
Thanks you for the tip….(of deleting the app). I spent about an hour too like mcnus!
Sam
Same problem but after 3 days of struggling with this problem I came across your post which solved my problem in 10 seconds. Thanks a lot.
That’s exactly why I made it. Glad it could be of help.
I have the same problem. I’ve downloaded a complete Xcode project which worked perfectly. However, I needed more columns in the table, so what I did was I created a new database and created a new table. Then I edited the code by replacing the original database and table by the once I created. Here my problem started. Even if I replace the database and table I have created by the original once, i still get the message “no such table: table_name”
I have deleted the app from simulator, deleted the database i created from my MAC and even i rest my simulator.
WHAT CAN I DO PLEASE?