title: Using `executemany` to update entries in an existing SQLite3 database (using Python sqlite3)
body: <p>I know that <code>executemany</code> can be used to conveniently add new entries to a database; useful to reduce the Python method-call overheads compared to single <code>execute</code>s in a for loop. However, I am wondering if this could work with SQLite's <code>UPDATE</code>. </p>
  
  <p>More concretely, consider the following setup:</p>
  
  <pre><code>cnx = sqlite3.connect(DATABASE)
  c = cnx.cursor()
  for path in paths:
      for data in some_computation(path):
          c.execute("UPDATE TABLENAME SET cont=? WHERE id=?", (data[1], data[0]))
  cnx.commit()
  cnx.close()
  </code></pre>
  
  <p>I am not even sure if the approach below would be any faster (would have to benchmark it), but the problem is that it doesn't work, because I am doing it incorrectly I assume. Any tips to use <code>executemany</code> in the code snippet below to accomplish the task that I posted above?</p>
  
  <pre><code>cnx = sqlite3.connect(DATABASE)
  c = cnx.cursor()
  
  for path in paths:
      data_ids, data_conts = [], []
      for data in some_computation(path):
          if len(data_ids) &gt;= CHUNKSIZE:
              c.executemany("UPDATE TABLENAME SET cont=? WHERE id=?", (data_conts, data_ids))
              cnx.commit()
              data_ids, data_conts = [], []
          data_ids.append(data[0])
          data_conts.append(data[1])
      c.executemany("UPDATE TABLENAME SET cont=? WHERE id=?", (data_conts, data_ids))      
      cnx.commit()
  
  cnx.commit()
  cnx.close()
  </code></pre>
  
  <p>Many thanks for tips and insights!</p>
  
  <p><strong>EDIT 1:</strong> </p>
  
  <p>The problem with the bottom example:</p>
  
  <pre><code>ProgrammingError: Incorrect number of bindings supplied. The current statement uses 2, and there are 50000 supplied.
  </code></pre>
  
  <p>(where CHUNKSIZE=50000)</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>The same error occurs</p>
  
  <pre><code>cnx = sqlite3.connect(DATABASE)
  c = cnx.cursor()
  
  for path in paths:
      data_conts = []
      for data in some_computation(path):
          if len(data_ids) &gt;= CHUNKSIZE:
              c.executemany("UPDATE TABLENAME SET cont=? WHERE id=?", (data_conts,))
              cnx.commit()
              data_conts = []
  
          data_conts.append([data[1], data[0]])
      c.executemany("UPDATE TABLENAME SET cont=? WHERE id=?", (data_conts,))   
      cnx.commit()
  
  cnx.commit()
  cnx.close()
  </code></pre>
  
  <p>but thanks to @falsetru I then noticed my error, It should be </p>
  
  <pre><code>... WHERE id=?", data_conts)
  </code></pre>
  
  <p>and not </p>
  
  <pre><code>... WHERE id=?", (data_conts,))
  </code></pre>