0

我正在开发一个 iOS 应用程序,自从迁移到 Xcode 5 和 IOS7 后我遇到了一些问题。在 ios7 设备上进行测试时,我无法写入数据库。在模拟器中工作正常(iOS 7)。在 iOS 6 设备上工作正常。

这是我写入 sqlite3 数据库的代码。之后我从同一个数据库中读取,但值没有改变。在多个设备上进行了测试。

提前致谢。

 sqlite3 *db9;
    @try {
        NSFileManager *fileMgr9 = [NSFileManager defaultManager];
        NSString *dbPath9 = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"db.sqlite3"];
        BOOL success9 = [fileMgr9 fileExistsAtPath:dbPath9];
        if (!success9) {
            NSLog(@"Cannot locate database file '%@'.", dbPath9);
        }

        else NSLog(@"Database file located at: '%@'.", dbPath9);
        if (!(sqlite3_open([dbPath9 UTF8String], &db9) == SQLITE_OK)) {
            NSLog(@"An error has occured");
        }


        NSString *strSQL9 = [NSString stringWithFormat:@"UPDATE teste SET scor = ?, timp = ? WHERE id = ?"];


        const char *sql9 = [strSQL9 UTF8String];


        sqlite3_stmt *sqlStatement9;
        if (sqlite3_prepare(db9, sql9, -1, &sqlStatement9, NULL) != SQLITE_OK) {
            NSLog(@"Problem with prepare statement");
        }else

        {
            NSLog(@"middle of it - scrie");

            if (scordb1 == 0) {
                sqlite3_bind_int(sqlStatement9, 1, scorTestTotal);
            }else
                sqlite3_bind_int(sqlStatement9, 1, ((scorTestTotal+scordb1)/2));


            sqlite3_bind_int(sqlStatement9, 2, timeInterval);
            sqlite3_bind_int(sqlStatement9, 3, vasile);

            sqlite3_step(sqlStatement9);
            int success = sqlite3_step(sqlStatement9);
            sqlite3_reset(sqlStatement9);

            if (success == SQLITE_ERROR){ NSLog(@"error write");}
            else {NSLog(@"success write");}



        }


        sqlite3_finalize(sqlStatement9);
        sqlite3_close(db9);
        NSLog(@"Close db SCRIE db9");

    }
    @catch (NSException *exception) {
        NSLog(@"An exception occured: %@", [exception reason]);

    }
4

0 回答 0