I have to make an sqlite db from data fetched from a JSON API. The code is working fine and its adding them one by one via a for loop, but the api response time is 1 sec per hit, so 34000 seconds plus inserting them in sqlite through code will take about 9 hours. Is there any way to speed up this?
Edit: i am using Objective C/sqlite3 framework/Xcode 4.2
Heres the Code...
dbPath=[self.databasePath UTF8String]; if(sqlite3_open(dbPath,&database)==SQLITE_OK) { // sqlite3_exec(database, "BEGIN", 0, 0, 0); const char *sqlstatement="insert into artist values(?,?,?,?,?)"; sqlite3_stmt *compiledstatement; if(sqlite3_prepare_v2(database,sqlstatement , -1, &compiledstatement, NULL)==SQLITE_OK) { for(i=4611;i<=34803;i++) { NSURLResponse *response; NSError *err; NSData *data= [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"API&id=%i",i]]] returningResponse:&response error:&err]; if(data.length>0) { NSError *err; NSDictionary *jsonDict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&err]; // sqlite3_exec(database, "BEGIN", 0, 0, 0); sqlite3_bind_text(compiledstatement,1,[[[[jsonDict objectForKey:@"artistDetail"]objectForKey:@"artist"]objectForKey:@"id"] UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(compiledstatement,2,[[[[jsonDict objectForKey:@"artistDetail"]objectForKey:@"artist"]objectForKey:@"name"] UTF8String], -1, SQLITE_TRANSIENT); if([[[jsonDict objectForKey:@"artistDetail"]objectForKey:@"artist"]objectForKey:@"description"]) sqlite3_bind_text(compiledstatement,3,[[[[jsonDict objectForKey:@"artistDetail"]objectForKey:@"artist"]objectForKey:@"description"] UTF8String], -1, SQLITE_TRANSIENT); else sqlite3_bind_text(compiledstatement,3,[@"" UTF8String], -1, SQLITE_TRANSIENT); if([[[[jsonDict objectForKey:@"artistDetail"]objectForKey:@"artist"]objectForKey:@"links"]objectForKey:@"website"]) sqlite3_bind_text(compiledstatement,4,[[[[[jsonDict objectForKey:@"artistDetail"]objectForKey:@"artist"]objectForKey:@"links"]objectForKey:@"website"] UTF8String], -1, SQLITE_TRANSIENT); else sqlite3_bind_text(compiledstatement,4,[@"" UTF8String], -1, SQLITE_TRANSIENT); if([[[[[[jsonDict objectForKey:@"artistDetail"]objectForKey:@"artist"]objectForKey:@"media"]objectForKey:@"low_res_images"]objectAtIndex:0]objectForKey:@"url"]) sqlite3_bind_text(compiledstatement,5,[[[[[[[jsonDict objectForKey:@"artistDetail"]objectForKey:@"artist"]objectForKey:@"media"]objectForKey:@"low_res_images"]objectAtIndex:0] objectForKey:@"url"] UTF8String], -1, SQLITE_TRANSIENT); else sqlite3_bind_text(compiledstatement,5,[@"" UTF8String], -1, SQLITE_TRANSIENT); if(sqlite3_step(compiledstatement)==SQLITE_DONE) { NSLog(@"done %i",i); } else NSLog(@"ERROR"); } sqlite3_reset(compiledstatement); } } } else NSLog(@"error"); sqlite3_close(database);