1

我使用 FMDB executeUpdate 在下面的插入语句中获得了 EXC_BAD_ACCESS。它发生在 FMDatabase 中的 bindObject toColumn 上。

在 NSlog 语句中,我得到了正确的值,但更新语句被炸毁了。不知道我在这里做错了什么。

- (void) addSubject {

    DrillDownAppAppDelegate *appDelegate = (DrillDownAppAppDelegate *)[[UIApplication sharedApplication] delegate];

    FMDatabase *database = [FMDatabase databaseWithPath:appDelegate.getDBPath];    
    [database open];

    NSLog(@"SUBJECT_ID/TITLE/CATEGORY_TITLE = %d / %@ / %@", self.subject_id, self.title, self.category_title);

    [database executeUpdate:@"insert into SUBJECT (subject_id, subject, category) values(?, ?, ?)", 
    self.subject_id, self.title, self.category_title, nil];

    [database close];

}

我浏览了 FMDatabase 代码,它看起来像第一个变量,subject_id 是爆炸的那个。我尝试同时保存为 NSInteger 和 NSNumber 并且都给出了同样的崩溃。

FMDatabase 中崩溃的确切行是:

    else if ([obj isKindOfClass:[NSData class]]) {

并且它将 subject_id 作为 NSInteger(或 NSNumber)传递并给出错误。

4

1 回答 1

2

FMDB executeUpdate 语句要求您使用 NSNumber 而不是 NSInteger,因此将您的 NSInteger 转换为 NSNumber 作为 executeUpdate 语句的一部分,它将起作用。我花了几个小时寻找这个,终于找到了。

以下是它的外观示例:

[database executeUpdate:@"update Subject Set subject = ?, category = ? where subject_id = ?", self.title, self.category_title, [NSNumber numberWithInt:self.subject_id]];
于 2012-01-30T06:21:58.987 回答