【问题标题】:How do I see success of the following FMDatabase executeUpdate statement?如何查看以下 FMDatabase executeUpdate 语句是否成功?
【发布时间】:2015-05-23 14:31:40
【问题描述】:

以下代码没有给出任何错误,但没有进行插入,我不知道为什么。我还是个新手,想知道查看此查询结果或查看是否有错误消息的最佳方法。我确定它很简单,例如“BOOL 成功 = [数据库执行更新...] 然后打印 BOOL。提前致谢。

if ([database open]) {
    [database executeUpdate:@"insert into CONDITION (condition_id, condition_name, condition_detail, condition_area, condition_date, active) values(?, ?, ?, ?, ?)",
    [NSNumber numberWithInt:self.condition_id], self.condition_name, self.condition_detail, self.condition_area, self.condition_date, [NSNumber numberWithInt:myInt] ];

    [database close];

【问题讨论】:

  • 这行不通,因为您有五个 ? 占位符,但有六个列/值。

标签: ios sql fmdb


【解决方案1】:

executeUpdate方法有返回值,FMDatabase保存lastErrorMessage

BOOL isSuccessful = [database executeUpdate:@"insert into CONDITION (condition_id, condition_name, condition_detail, condition_area, condition_date, active) values(?, ?, ?, ?, ?)",
    [NSNumber numberWithInt:self.condition_id], self.condition_name, self.condition_detail, self.condition_area, self.condition_date, [NSNumber numberWithInt:myInt] ];
if (!isSuccessful) {
    NSLog(@"%@", database.lastErrorMessage);
}

【讨论】:

  • 感谢 Bannings 快速且非常有帮助的回复!这正是我所需要的,我现在看到了错误消息并且可以继续。
猜你喜欢
  • 2011-05-07
  • 2016-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-11
  • 1970-01-01
相关资源
最近更新 更多