tags:

views:

48

answers:

1

Hi am new in this field.i am trying out one app. i am storing data in sqlite database. i am only using sqlite for my app when i add data into table from my app, I can see changes in my simulator but when i check my database there is no change and when i reset my simulator all my added data is gone. Please help me. i don't know what is wrong. there is no error.

A: 

When you say "reset my simulator" does that mean quit the app and restart it, or use the "Reset Content and Settings" option from the iPhone Simulator menu?

Doing the latter will erase all simulator apps' data, but doing the former should not.

How and where are you creating the database file that you intend to write to?

The correct thing to do is generally the following:

Put an empty copy of the database (probably with necessary tables created and any initial data already entered) in your app's bundle.

On app launch, check for the existence of the database file in your app's Documents directory. If it doesn't exist, copy it from the bundle to Documents. If it does exist, do nothing.

Your app should write to the copy of the database in your app's Documents directory. This means that the database in your app's bundle will (and must) stay the same, but the one in Documents will contain any new data.

admanimal
I 'Rest content and setting" and also i check database table from terminal.there is no changes.only whatever i added from terminal when i create table.
shil678
Reset content and settings will erase anything associated with apps you have installed in the simulator. What is the exact location of the file you are looking at in terminal?
admanimal
I create my db in one folder which is located in userfolderexact address userfolder/sqlitedb/coffee.sqlite
shil678
I create table from terminal and also i insert some values too.when i run first time the app shows me my database values after that i can not see changes. when insert some more data in my database from terminal and again run the app it did not show be update data. i have no idea whats going on.please help i have to understand this logic
shil678
Did you follow the steps in my original answer about how to correctly set up a writable copy of your database in the app's documents directory? The only file that can and should be written to by the app while running in the simulator will be one that is located in /Users/(Your User Name)/Library/Application Support/iPhone Simulator/(version)/Applications/(app's UUID)/Documents/coffee.sqlite, which you must create when the app first runs (just the file in the Documents directory, not the whole path). The original file that you added to your XCode project will not be written to.
admanimal
Apple used to provide a sample project called SQLiteBooks that shows exactly what you must do. They don't provide it anymore as they now promote the use of Core Data (i.e. CoreDataBooks), but you can google SQLiteBooks to find a copy.
admanimal
Hi Thanks for Help, But i can't find SQLiteBooks example in google or any where else there is lots of comments on it but no coding if you know any link can you Please send it to me. Thanks... again.
shil678
Which location you give me i check there i can see my data there. is that means my whole add data will be there not where i created.
shil678
Yes. The original database that you created will end up in the app bundle, which can not be written to by the app. Somewhere, probably in your app delegate, you apparently create a copy of that file in your app's Documents directory, which you do have write access to.If the file at that long path that I gave in my previous comment does exist, then you are doing things correctly- you just need to make sure you understand what you are doing.
admanimal
sorry for my silly questions but i am trying to understand sqlite if my app is running on my iphone some how my phone switch off or i have to reset it then what will happen to my database.Is there any place i can put my database safe.
shil678
Read the Files and the File System subsection of the Implementing Standard Application Behaviors section of the iPhone Application Programming Guide.There is a big difference between sleeping or shutting off your phone and using the "reset content and settings" option in the Simulator. The former two will leave your app's data in tact (if put in the right place) but the latter will erase everything.
admanimal