簡體   English   中英

使用包裝器時,語句不會在sqlite3中提交

[英]Statements are not getting committed in sqlite3 when using the 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);

它確實打印了波西塔諾..但是當我只是再次打印時沒有更新查詢。 我得到了巴黎的舊條目。 我試過[sqlite commit]; 這也行不通。 即使我創建了一個簡單的表,它也是第一次執行然后當我點擊創建按鈕時它表示該表已經存在但是當我再次重新運行它再次創建表而不是給我一個表已經存在的錯誤。

我究竟做錯了什么 ??? 我正在使用http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/ wrapper。

問候,新手

看起來你沒有提交交易。

在文件Sqlite.m中,有beginTransaction和commit方法。 或者您可以嘗試將db設置為自動提交模式。

-(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]);
    }
}

在xxxxAppdelegate.m中

那就是解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM