fmdb executeUpdate失败

时间:2012-02-19 06:56:26

标签: objective-c

我做错了什么?这是一个非常简单的陈述,但无法弄清楚导致它失败的原因

    FMDatabase *db = [FMDatabase databaseWithPath:appDelegate.databasePath];
    [db open];
        isSuccess = [db executeUpdate:@"INSERT INTO notes (title, comment, fk) values (?, ?, ?);", title, comment, fkID];

exception.name = NSInvalidArgumentException,exception.reason = - [__ NSCFString comment]:无法识别的选择器发送到实例0x68a93f

Note.h

#import <Foundation/Foundation.h>

@interface Note : NSObject

@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *comment;
@property (nonatomic) int fkID;

2 个答案:

答案 0 :(得分:9)

看看FMDB usage

[db executeUpdate:@"INSERT INTO notes VALUES (?,?,?)", title, comment, [NSNumber numberWithInt:fkID]];  

提供给-executeUpdate:方法(或接受va_list作为参数的任何变体)的所有参数都必须是对象。

答案 1 :(得分:-3)

这是我最终做的事情。

    NSString *sql = [NSString stringWithFormat:@"INSERT INTO notes (title, comment, fkid) values ('%@', '%@', %i)", title, comment, fkid];
    isSuccess = [db executeUpdate:sql];

工作正常。