如果我调用-(void)insertDataIntoAssemblyAssessment
方法,wherefinalAssembIdArr
是一个数组,其中必须有多个值,那么我会收到一个错误,即“数据库已锁定”。但是,如果 infinalAssembIdArr
只有一个值,则值成功存储在数据库中。
我该如何解决这个问题?请帮我。
-(void)insertDataIntoAssemblyAssessment
{
sqlite3_stmt *fstatement;
const char *dbpath = [databasePath UTF8String];
for(int cnt=0; cnt < [finalAssembIdArr count]; cnt++)
{
finalAsmbId2=[finalAssembIdArr objectAtIndex:cnt];
NSLog(@"finalAsmbId2...%@",finalAsmbId2);
NSLog(@"finalAssessmentIdSt2...%@",finalAssessmentIdSt2);
NSLog(@"finalFacIdSt2...%@",finalFacIdSt2);
NSLog(@"finalSpaceIdSt2...%@",finalSpaceIdSt2);
if (sqlite3_open(dbpath, &ipadSites) == SQLITE_OK)
{
NSLog(@"db opened for AssemblyAssessment..");
NSString *insertfSQL = [NSString stringWithFormat:@"INSERT INTO AssemblyAssessment (assessmentid,spaceid,assemblyid,FacilityID) VALUES (\"%@\",\"%@\",\"%@\",\"%@\")",self.finalAssessmentIdSt2,self.finalSpaceIdSt2,self.finalAsmbId2,self.finalFacIdSt2];
NSLog(@"insertfSQL...%@",insertfSQL);
const char *insert_fstmt = [insertfSQL UTF8String];
sqlite3_prepare_v2(ipadSites,insert_fstmt,-1,&fstatement,NULL);
NSLog(@"inserting AssemblyAssessment..");
if (sqlite3_step(fstatement) == SQLITE_DONE)
{
NSLog(@"Add value in AssemblyAssessment...");
}
else
{
NSLog(@"Insert failed: %s", sqlite3_errmsg(ipadSites));
NSLog(@"Failed to add value in AssemblyAssessment...");
}
}
sqlite3_finalize(fstatement);
sqlite3_close(ipadSites);
}
}