1

Hi i am using FMDB to retrieve data from SQLITE database.

db  = [[FMDatabase alloc] initWithPath:path];   
[db open];  
FMResultSet *fResult= [db executeQuery:@"SELECT * FROM Users"];

aUsers = [[NSMutableArray alloc] init];
while([fResult next])
{
    userData = [fResult stringForColumn:@"Name"];       
    lblUsers.text=[lblUsers.text  stringByAppendingString:userData];
    [aUsers addObject:userData];        
    NSLog(@"The data is %@=",userData);
}   
[db close];
[aUsers release];
[db release];

So i got output to this program is

Sachin Rahul Dravid

But when i try to insert data to the databse, i used the following coding

   [db beginTransaction];
[db executeUpdate:@"insert into users (name) values('Balaji R')" ,nil];
[db commit];

Now i again retrieve the data from database. So i got a output like this

Sachin Rahul Dravid Balaji R

But when i quit my application and then bulid it again, Now i am seeing only the old records

Sachin Rahul Dravid

The inserted recorded "Balaji R" gone away!

Anybody know where i did the mistake?Please tell me the solution......

3
  • 1
    I've worked with SQLite in VisualStudio, and every time I do a build, it copies the SQLite database file from the resources folder to the bin folder. This means every build/execute will start with the same base version of the db and changes made to the database during one debugging session don't persist to the next. Not sure if you're experiencing the same phenomenon... Commented Aug 13, 2010 at 13:54
  • what is the value of path? executeUpdate returns a BOOL check the return value. The ,nil after the SQL string is unnecessary Commented Aug 13, 2010 at 14:16
  • path value is /Users/balajir/Library/Application Support/iPhone Simulator/4.0.1/Applications/7E4DB460-41B2-4AD4-B80C-7E4735104C15/DBTesting.app/MyDataNew.sql executeUpdate returns "YES". Is there any way to persist the data in database? Commented Aug 16, 2010 at 5:09

1 Answer 1

2

You are trying to write to the app bundle directory which is not allowed. You have to copy your starting database to the user's Documents directory and pass the path of the copy to the FMDB initWithPath: Take a look at the iOS Application Programming Guide. Take a look at the CoreDataBooks sample code. The App Delegate has code in the persistentStoreCoordinator method that you can use as a guide for your implementation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.