开发者

SQLite database not refreshing in iPhone simulator

开发者 https://www.devze.com 2023-03-18 01:44 出处:网络
So I got SQLite database working for my app. It loads text values from database, copies it to the array and displays it in Table View.

So I got SQLite database working for my app. It loads text values from database, copies it to the array and displays it in Table View.

The first time I got it going i had the values Tuesday, Thursday, Saturday displaying. Then I modified the database using SQLite Manager add-on for firefox (I开发者_运维技巧 also used it to create it) by adding new values. However, the new values are not displaying, and even if I delete values like Saturday, the same old "Tuesday, Thursday, Saturday" keeps reappearing. I'm baffled.

Notes:

  • I tried restarting Xcode and even the computer lol.
  • When I modify database in SQLite Manager, the update time on database file is refreshed in Xcode.
  • My database management, just like in the tutorial, happens in AppDelegate.
  • In appdelegate: (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions I have this code at beginning

    routines = nil; // Reset array
    database = nil; // not opened yet
    selStmt = nil; // no compiled statement yet
    updStmt = nil; // no compiled statement yet
    

I'm following this tutorial and modifying it on my needs: http://technologyservants.com/index.php?option=com_content&view=article&id=46:shopping-list-an-iphone-sqlite-tutorial


You're probably copying the database from the app bundle into the documents directory if it doesn't already exist in the documents directory.

The next time you run your app (with a new db) you check that the db exists in the user's documents directory and then you're probably not copying it again. You're not comparing the versions of the db, you're just checking that a db with that name exists.

If you're in development still, an easy solution is to just clear reset the content and settings of the simulator, which will cause your app to copy the db again.


As Firoze stated (I only skimmed the tutorial so forgive me if I'm wrong) on the first load the database is copied from the bundle and into the documents directory. For each launch after that there is no need to copy the database out as it already exists.

If you are working on the simulator and want to change the data so it is reflected live while you work you need to open the database located at

/Users/<username>/Library/Application Support/iPhone Simulator/4.3.2/Applications/<app bundle identifier>/Documents/<database file>

The file may not be in that exact location but it gives you an idea of where to start looking around

0

精彩评论

暂无评论...
验证码 换一张
取 消