Based on a background other than SQL, I create a simple table called test with three fields:
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; }
when I insert a record into the table, I got an exc_bad_access error:
if (![db executeUpdate:@"insert into test values(?,?,?)", NULL, 1, @"HELLO"]) { NSLog(@"insert test, %d:%@", [db lastErrorCode], [db lastErrorMessage]); return NO; }
If I change the column type "userid" from integer to text, this will work well. And I am testing the table using the sqlite command on the console, it works too. Guys, what do you think? Thanks...
I will try another way to deal with this problem:
if (![db executeUpdate:@"insert into test values(?,?,?)", NULL, [NSNumber numberWithInt:1], @"HELLO"]) { NSLog(@"testint, %d:%@", [db lastErrorCode], [db lastErrorMessage]); return NO; }
then it works. I canβt say the reason ... Maybe fmdb only supports inserting an object.