views:

48

answers:

2
[sqlite executeQuery:@"UPDATE UserAccess SET Answer ='Positano';"];
NSArray *query2 = [sqlite executeQuery:@"SELECT Answer FROM UserAccess;"]; 
NSDictionary *dict = [query2 objectAtIndex:0]; 
NSString *itemValue = [dict objectForKey:@"Answer"]; 
NSLog(@"%@",itemValue);

It does print Positano at this point .. But when I just print without the update query again . I get the old entry which is Paris. I tried [sqlite commit]; which also doesn't work. Even if I create a simple table it executes the first time then again when I hit the create button it says that the table already exists BUT when I rerun again it creates the table again instead of giving me an error that the table already exists .

What am I doing wrong ??? I am using http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/ wrapper.

Regards , Novice

+2  A: 

It looks like you didn't commit the transaction.

In the file Sqlite.m, there are methods beginTransaction and commit. Or you may try to set the db to the autocommit mode.

Krab
How can I do that ?
@Krab .. would you please give me an example . I am sorry .. I am new to Objective C
A: 
-(void)createEditableCopyOfDatabaseIfNeeded 
{
    // Testing for existence
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"MyDatabase.sqlite"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"MyDatabase.sqlite"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if(!success)
    {
        NSAssert1(0,@"Failed to create writable database file with Message : '%@'.",[error localizedDescription]);
    }
}

In xxxxAppdelegate.m

That was the solution