我正在使用 FMDatabase 对 sqlite3 数据库进行操作。这是我的代码:
NSString *dbFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"temp_info.db"]];
FMDatabase *fmdb = [FMDatabase databaseWithPath:dbFilePath];
if (![fmdb open]) {
NSLog(@"......");
} else {
NSString *sql = @"CREATE TABLE IF NOT EXISTS test1(id INTEGER, name TEXT, create_time TEXT)";
if (![fmdb executeUpdate:sql]) {
NSLog(@"......");
}
for (int i = 0; i < 3; i++) {
BOOL result = [fmdb executeUpdate:@"INSERT INTO test1(id, name, create_time) values(?,?,?)", i+1, @"test", @"12-09-10 12:10"];
NSLog(@"%d", result);
}
// EXC_BAD_ACCESS
}
当我运行该行时:
BOOL result = [fmdb executeUpdate:@"INSERT INTO test1(id, name, create_time) values(?,?,?)", i+1, @"test", @"12-09-10 12:10"];
我得到一个EXC_BAD_ACCESS
错误。为什么?