8

If I call this method, then I get an error that is & ldquo; The database is...

 2 years ago
source link: https://www.codesd.com/item/if-i-call-this-method-then-i-get-an-error-that-is-the-database-is-lock-how-can-i-solve-this-help-me-please.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

If I call this method, then I get an error that is & ldquo; The database is lock & rdquo ;. How can I solve this? Help me please

advertisements

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK