title: Android Sqlite Transaction and Content Provider
body: <p>I'm Parsing a JSON WebService and creating a array with data to INSERT and DELETE entries in a database.</p>
  
  <p>I found the solution <code>bulkInsert</code> to insert multiple rows using database transactions inside a content provider, however, I am trying to do the same procedure to delete multiple lines.</p>
  
  <p>The INSERT solution:</p>
  
  <pre><code>@Override
  public int bulkInsert(Uri uri, ContentValues[] allValues) {
  
      SQLiteDatabase sqlDB = mCustomerDB.getWritableDatabase();
  
      int numInserted = 0;
      String table = MyDatabase.TABLE;
  
      sqlDB.beginTransaction();
  
      try {
          for (ContentValues cv : allValues) {
              //long newID = sqlDB.insertOrThrow(table, null, cv);
              long newID = sqlDB.insertWithOnConflict(table, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
              if (newID &lt;= 0) {
                  throw new SQLException("Error to add: " + uri);
              }
          }
          sqlDB.setTransactionSuccessful();
          getContext().getContentResolver().notifyChange(uri, null);
          numInserted = allValues.length;
      } finally {
          sqlDB.endTransaction();
      }
  
      return numInserted;
  }
  </code></pre>
  
  <p>Using this call:</p>
  
  <pre><code>mContext.getContentResolver().bulkInsert(ProviderMyDatabase.CONTENT_URI, valuesToInsertArray);
  </code></pre>
  
  <p>Is there any way to delete multiple rows (with this array ID's) of database using content provider.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I found this solution, using the `IN clause:</p>
  
  <pre><code>List&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
  for (ContentValues cv : valuesToDelete) {
      Object value = cv.get(DatabaseMyDatabase.KEY_ROW_ID);
      list.add(value.toString());
  }
  
  String[] args = list.toArray(new String[list.size()]);
  String selection = DatabaseMyDatabase.KEY_ROW_ID + " IN(" + new String(new char[args.length-1]).replace("\0", "?,") + "?)";
  
  int total = mContext.getContentResolver().delete(ProviderMyDatabase.CONTENT_URI, selection, args);
  LOGD(TAG, "Total = " + total);
  </code></pre>
  
  <p>The problem is that, if the JSON return more than 1000 rows to insert, occurs error, because the SQLITE_MAX_VARIABLE_NUMBER is set to 999. It can be changed but only at compile time.</p>
  
  <pre><code>ERROR: SQLiteException: too many SQL variables
  </code></pre>
  
  <p>Thanks in advance</p>