当我尝试在我的数据库中插入一些东西时,我收到了这个错误:
奇怪的是,只有当我插入的表中有大约 12-14 条以前的记录时才会发生错误。有谁知道如何解决这个问题?
这是我的代码:
- (void)addToBasket:(id)sender {
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/MainDatabase.db", docDirectory];
databasePath = filePath;
db = [FMDatabase databaseWithPath:databasePath];
if (![db open]) { [db release]; return; }
NSInteger prodID = ((UIControl*)sender).tag;
[db executeUpdate:@"INSERT INTO order_items VALUES (?, ?, ?, ?)", @"", [NSNumber numberWithInt:prodID], orderID, [NSNumber numberWithInt:1], nil];
[basket insertObject:[NSNumber numberWithInt:prodID] atIndex:0];
[basketQA insertObject:[NSNumber numberWithInt:1] atIndex:0];
[basketItemName insertObject:@"test" atIndex:0];
[basketPrice insertObject:@"test" atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[db close];
}