title: Separate SQLite transactions in multiple threads
body: <p>My application's update process grabs data from three separate sources (e.g.,Twitter, Facebook, and Google). We update each at the same time in a separate thread for performance reasons and would like each one to have their own SQLite transaction since we may be processing ~500 items at once which can take several seconds.</p>
  
  <p>Is there a way to begin a new transaction in a thread which does not "interfere" with other threads interaction of the database?</p>
  
  <p>TLDR: Can you have multiple SQLite transactions across different threads?</p>
  
  <hr>
  
  <p><strong>Update</strong>: E.g., consider the following code:</p>
  
  <pre><code>@implementation Update
  
  - (void)prepareUpdate {
      [self update:@"Twitter"];
      [self update:@"Facebook"];
      [self update:@"Google"];
  }
  
  - (void)update:(NSString *)platform {
      dispatch_queue_t newThread = dispatch_queue_create("newThread", NULL);
      dispatch_async(newThread, ^{
  
          NSDictionary * data = [Platform getData:platform];
  
          [_db beginTransaction];
              for (id item in data) {
                  [Platform update:platform withData:item];
              }
          [_db endTransaction];
  
          dispatch_async(dispatch_get_main_queue(), ^{
  
              NSLog(@"Update complete!");
  
          });
      });
  }
  
  @end
  </code></pre>
  
  <p>Which will generate the following error:</p>
  
  <pre><code>Error whilst preparing query: cannot start a transaction within a transaction
  </code></pre>