If I call -(void)insertDataIntoAssemblyAssessment
method,where finalAssembIdArr
is an array in which must be more than one value, then i'm getting a error which is " database is lock ". But, if in finalAssembIdArr
have just one value,then,value are stored in database successfully.
How I can solve this?? Please help me.
-(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);
}
}
Please... ! Don't open/close SQLite connection in loop like that! Open handle to database outside from the "FOR loop". Please look here how to insert data into data base in iphone and here How to insert NSMutableArray elements in Sqlite3 in iPhone
And, for the basic CRUD (create, read, update, delete), I suggest you .. to take a look at FMDB
Have you opened the database in SQLite or any other browser ?? If database is opened from outside, it gives same error. Check it. I had same issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.