目前我正在为我的 iPhone 应用程序使用 FMDB 包装器。我的问题是,在执行 2000 条 SQL 插入语句(从 5000 到 8000 条 sql 语句中)后,出现以下错误:
“错误 14,无法打开数据库文件”
谁能帮我解决这个错误?
这是我的代码:
-(BOOL)insertOrUpdateinTable:(NSString *)tableName:(NSMutableArray *)columnName: (NSMutableArray *)columnValue {
[self initiateFMDB];
NSString *queryString=@"";
BOOL success;
//queryString =[[NSString alloc]init];
if (![db open]) {
NSLog(@"could not open db");
}
else {
//insert into Category(Categorycode,CategoryDesc) values (1,2)
queryString=[queryString stringByAppendingFormat:@"insert into %@(",tableName];
for (int cntCName=0; cntCName<[columnName count]; cntCName++) {
if (cntCName<[columnName count]-1){
queryString=[queryString stringByAppendingFormat:@"%@,",[columnName objectAtIndex:cntCName]];
}
else {
queryString=[queryString stringByAppendingFormat:@"%@",[columnName objectAtIndex:cntCName]];
}
}
queryString=[queryString stringByAppendingString:@") values ("];
for (int cntCValue=0; cntCValue<[columnValue count]; cntCValue++) {
if (cntCValue<[columnValue count]-1){
queryString=[queryString stringByAppendingFormat:@"'%@',",[columnValue objectAtIndex:cntCValue]];
}
else {
queryString=[queryString stringByAppendingFormat:@"'%@'",[columnValue objectAtIndex:cntCValue]];
}
}
queryString=[queryString stringByAppendingString:@")"];
// NSLog(@"QueryString=%@",queryString);
@try {
success=[db executeUpdate:[NSString stringWithFormat:@"%@",queryString]];
}
@catch (NSException *exception) {
NSLog(@"Exception error for selectFromItemPhoto is %@",[exception reason]);
}
}
if (success==TRUE) {
NSLog(@"Data inserted successfully");
}
else {
NSLog(@"Data is not inserted successfully");
}
// queryString=nil;
// [queryString release];
if ([db open]) {
[db close];
}
return success;
}