title: Fastest way to insert many rows into sqlite db on iPhone
body: <p>Can someone explain what the best way to insert a lot of data on the iPhone using FMDB is?  I see things like using the beginTransaction command.  I'm honestly not sure what this or setShouldCacheStatements do.  I followed what code my coworker did so far, and this is what it looks like:</p>
  
  <pre><code>BOOL oldshouldcachestatements = _db.shouldCacheStatements;
  [_db setShouldCacheStatements:YES];
  [_db beginTransaction];
  NSString *insertQuery = [[NSString alloc] initWithFormat:@"INSERT INTO %@ values(null, ?, ?, ?, ?, ?, ?, ?);", tableName];
  [tableName release];
  BOOL success;
  
  bPtr += 2;
  int *iPtr = (int *)bPtr;
  int numRecords = *iPtr++;
  
  for (NSInteger record = 0; record &lt; numRecords; record++) {
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
      // Some business logic to read the binary stream  
  
      NSNumber *freq = aFreq &gt; 0 ? [NSNumber numberWithDouble:100 * aFreq / 32768]: [NSNumber numberWithDouble:-1.0];
  
      // these fields were calculated in the business logic section
      success = [_db executeUpdate:insertQuery,
                 cID,                                                                                                   
                 [NSNumber numberWithInt:position],                                                                       
                 [NSString stringWithFormat:@"%@%@", [self stringForTypeA:typeA], [self stringForTypeB:typeB]],     // methods are switch statements that look up the decimal number and return a string
                 [NSString stringWithFormat:@"r%i", rID],                                                               
                 [self stringForOriginal:original],                                                                    
                 [self stringForModified:modified],                                                                    
                 freq];
  
      [pool drain];
  }
  [outerPool drain];
  
  [_db commit];
  [_db setShouldCacheStatements:oldshouldcachestatements];
  </code></pre>
  
  <p>Is this the fastest I can do?  Is the writing the limitation of sqlite?  I saw this: <a href="http://www.sqlite.org/faq.html#q19" rel="noreferrer">http://www.sqlite.org/faq.html#q19</a> and wasn't sure if this implementation was the best with fmdb, or if there was any other thing I can do.  Some other coworkers mentioned something about bulk inserts and optimziing that, but I'm not honestly sure what that means since this is my first sqlite encounter.  Any thoughts or directions I can go research?  Thanks!</p>