Statements are not passed to sqlite3 when using a wrapper

[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);

He is printing Positano at that moment. But when I just print without asking for an update again. I get an old record, which is Paris. I tried [sqlite commit]; which also does not work. Even if I create a simple table, it runs the first time, and then again, when I click the Create button, it says that the table already exists. BUT, when I restart again, it creates the table again instead of giving me the error that the table already exists.

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

Regards, Beginners

+3
source share
2 answers
-(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

It was a decision

0
source

It looks like you did not complete the transaction.

There are beginTransaction and commit methods in the Sqlite.m file. Or you can try setting db to autocommit mode.

+2
source

Source: https://habr.com/ru/post/1742754/


All Articles