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只支持对象插入.
解决方法 我相信FMDB需要替换的对象?和int不是对象.将1更改为[NSNumber numberWithInt:1]此外,在您打开数据库的地方,您有类似的内容吗?
db = [FMDatabase databaseWithPath:writableDBPath]; if ([db open]) {
添加[db setTraceExecution:TRUE];紧接着它,它将为您记录您的sql文本.
可以先创建sql Nsstring,然后插入int,然后让FMDB运行已填充的字符串.
总结以上是内存溢出为你收集整理的FMDB sqlite插入失败全部内容,希望文章能够帮你解决FMDB sqlite插入失败所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)