来自非sql背景,我创建了一个名为test的简单表,包含3个字段:
NSString *testtable = @"create table if not exists test(testid integer primary key,userid integer,contentid text)"; if (![db executeUpdate:testtable]) { NSLog(@"create test,%d:%@",[db lastErrorCode],[db lastErrorMessage]); return NO; }
当我向表中插入记录时,我收到了一个exc_bad_access错误:
if (![db executeUpdate:@"insert into test values(?,?,?)",NULL,1,@"HELLO"]) { NSLog(@"insert test,[db lastErrorMessage]); return NO; }
如果我将列’userid’类型从整数更改为文本,这将很有效.我在控制台上使用sqlite命令测试表,它也运行良好.
你们有什么感想?谢谢…
我尝试另一种方法来处理这个问题:
if (![db executeUpdate:@"insert into test values(?,[NSNumber numberWithInt:1],@"HELLO"]) { NSLog(@"testint,[db lastErrorMessage]); return NO; }
然后它工作.我不能说出原因……也许fmdb只支持对象插入.