Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the routine I generally use to insert data in bulk.. </p> <pre><code>static sqlite3 *masterDB; static sqlite3_stmt *init_statement = nil; { NSString* statement; statement = @"BEGIN EXCLUSIVE TRANSACTION"; if (sqlite3_prepare_v2(masterDB, [statement UTF8String], -1, &amp;init_statement, NULL) != SQLITE_OK) { printf("db error: %s\n", sqlite3_errmsg(masterDB)); return NO; } if (sqlite3_step(init_statement) != SQLITE_DONE) { sqlite3_finalize(init_statement); printf("db error: %s\n", sqlite3_errmsg(masterDB)); return NO; } NSTimeInterval timestampB = [[NSDate date] timeIntervalSince1970]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MMM dd, yyyy"]; NSDate *now = [NSDate date]; NSString *dateTime = [dateFormat stringFromDate:now]; [dateFormat release]; statement = @"insert into table(id, name) values(?,?)"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(masterDB, [statement UTF8String], -1, &amp;compiledStatement, NULL) == SQLITE_OK) { for(int i = 0; i &lt; [aryList count]; i++){ NSString *objName = [aryList objectAtIndex:i]; sqlite3_bind_int(compiledStatement, 1, i ); sqlite3_bind_text(compiledStatement, 2, [objName UTF8String], -1, SQLITE_TRANSIENT); while(YES){ NSInteger result = sqlite3_step(compiledStatement); if(result == SQLITE_DONE){ break; } else if(result != SQLITE_BUSY){ printf("db error: %s\n", sqlite3_errmsg(masterDB)); break; } } sqlite3_reset(compiledStatement); } timestampB = [[NSDate date] timeIntervalSince1970] - timestampB; NSLog(@"Insert Time Taken: %f",timestampB); // COMMIT statement = @"COMMIT TRANSACTION"; sqlite3_stmt *commitStatement; if (sqlite3_prepare_v2(masterDB, [statement UTF8String], -1, &amp;commitStatement, NULL) != SQLITE_OK) { printf("db error: %s\n", sqlite3_errmsg(masterDB)); return NO; } if (sqlite3_step(commitStatement) != SQLITE_DONE) { printf("db error: %s\n", sqlite3_errmsg(masterDB)); return NO; } // sqlite3_finalize(beginStatement); sqlite3_finalize(compiledStatement); sqlite3_finalize(commitStatement); return YES; } return YES; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload