views:

118

answers:

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......

A: 

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.

falconcreek