SQLite3 nsInternalInconsistencyException

时间:2015-02-03 13:48:09

标签: objective-c sqlite

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'library routine called out of sequence'

这是我收到的错误消息。

ExposureViewController.m

- (IBAction)saveExposure:(id)sender {
    double sfd = [self.sfdField.text doubleValue];
    double thickness = [self.thicknessField.text doubleValue];
    int filmFactor = 35;
    double mAmins = 5.5;
    double density = 2.5;
    NSString *setUsed = @"Bay One Set";
    NSDate *currDate = [NSDate date];
    NSString *theDate = [NSString stringWithFormat:@"%@", currDate];

    Connection *dataBase = [[Connection alloc]init];

    [dataBase openDB];

    [dataBase saveTable:theDate withFieldSFD:sfd withFieldFilmFactor:filmFactor withFieldSet:setUsed withFieldThickness:thickness withFieldkV:kvValue withFieldmA:maValue withFieldmAmins:mAmins withFieldDensity:density];
}

这是我的IBAction,要求保存数据,在我的exposureViewController.m中

它连接到Connection.h以进行数据库查询等。

Connection.m

-(void)saveTable:(NSString *)dateField withFieldSFD:(float)field3 withFieldFilmFactor:(int)field4 withFieldSet:(NSString *)field5 withFieldThickness:(float)field6 withFieldkV:(int)field7 withFieldmA:(int)field8 withFieldmAmins:(float)field9 withFieldDensity:(float)field10
{
    NSString *sql = [NSString stringWithFormat:@"INSERT INTO exposures ('theDate', 'sfd', 'filmFactor', 'setUsed', 'thickness', 'kV', 'mA', 'mAmins', 'density') VALUES ('%@', '%.2f', '%i', '%@', '%.2f', '%i', '%i', '%.5f', '%.2f')", dateField, field3, field4, field5, field6, field7, field8, field9, field10];

    char *err;
    if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
        sqlite3_close(db);
        NSAssert(0, @"%s", sqlite3_errmsg(db));
    } else {
        NSLog(@"datasaved");
    }
}

所以我继续抛出这个错误,之前在添加openDB方法之前我会调用out of memory错误。但是排序之后我就遇到了这个问题。此外,如果这有助于表格的创建方式。

NSString *sql = [NSString stringWithFormat:
                 @"CREATE TABLE IF NOT EXISTS '%@' ( "
                 "INTEGER PRIMARY KEY, '%@' TEXT '%@' FLOAT, '%@' INTEGER, '%@' TEXT, '%@' FLOAT, '%@' INTEGER, '%@' INTEGER, '%@' FLOAT, '%@' FLOAT);", tableName, field2,field3,field4,field5,field6,field7,field8,field9,field10];

1 个答案:

答案 0 :(得分:0)

在断言错误之前关闭数据库。

在洗牌之后,我现在收到了抛出SQLITE_OK处理程序的真正错误。