So, I've read through every posts I found on internet but i still can't seem to make this work.
I'm trying to insert a huge amount of data into sqlite database. It's 20000 rows of data, so I have to do it in the background thread.
I have a NSObject .h and .m files to handle the database operations. And I call them from inside my main view.
Here's my code :
SQLiteDBHandler.m :
database = [FMDatabase databaseWithPath:[self getDBPath]];
[database open];
dispatch_queue_t q = dispatch_queue_create("FMDBQueue", NULL);
dispatch_async(q, ^{
for(Customer *c in arrayOfObjects) {
[database executeUpdate:@"INSERT INTO SNP(rdis, Position, FirstName, LastName) VALUES (?,?,?,?)", c.ID, c.Position, c.FirstName, c.LastName];
}
[database close];
});
and for calling the method in the main view, I call it this way :
SQLiteDBHandler *dbHandler = [[SQLiteDBHandler alloc]init];
[dbHandler insertDataIntoTable:mutableArray];
I've tried changing the FMDatabase with FMDatabaseQueue with no luck. So any help would be highly appreciated because I'm pretty desperate in this.
Thanks. Cheers!