title: Problem passing Tuple to MySQLdb in python
body: <p>I have some sql queries that work through python mysqldb to my mysql database, but i want to make them a little less sql-injection vulnerable so little bobby tables doesn't try to add data..</p>
  
  <p>for example:</p>
  
  <p><strong>ORIGINAL:</strong><br>
   (This works, so ListID etc is definitely valid)</p>
  
  <pre><code>sql="SELECT NAME FROM ListsTable WHERE ID=%s"%(ListID)  
  c.execute(sql)  
  </code></pre>
  
  <p><strong>ATTEMPTED WITH TUPLE:</strong>  </p>
  
  <pre><code>sql="SELECT NAME FROM ListsTable WHERE ID=%s"  
  c.execute(sql,(ListID,))  
  </code></pre>
  
  <p><strong>WORKS:</strong>  </p>
  
  <pre><code>sql="SELECT NAME FROM ListsTable WHERE ID=%s"  
  c.execute(sql, ListID)  
  </code></pre>
  
  <p>I don't know why that 2nd attempt doesn't work as a tuple but accepts it as a single parameter, but either way for another statement i need to pass multiple parameters so this won't work for that:</p>
  
  <p><strong>ORIGINAL:</strong>  </p>
  
  <pre><code>sql="SELECT * FROM ListsTable ORDER BY ID DESC LIMIT %s,%s"%(Page, (Page*20)+20)  
  c.execute(sql)
  </code></pre>
  
  <p>which works, but then this doesn't, again if i try to send the parameters as a tuple:</p>
  
  <pre><code>sql="SELECT * FROM ListsTable ORDER BY ID DESC LIMIT %s,%s"  
  var1=Page  
  var2=(Page*20)+20  
  params=(var1,var2)              
  c.execute(sql,params)  
  </code></pre>
  
  <p>or even just  </p>
  
  <pre><code>sql="SELECT * FROM ListsTable ORDER BY ID DESC LIMIT %s,%s"  
  c.execute(sql,(Page,(Page*20)+20))  
  </code></pre>
  
  <p>I've recently got this error on my webserver log, though note this MAY be a redherring due to the many different things I've been trying as it hasn't errored before: (The error refers to the above attempt of passing the "params" variable)</p>
  
  <pre><code>File "process.py", line 98, in main  
  c.execute(sql,params)  
  File "/var/www/cgi-bin/MySQLdb/cursors.py", line 159, in execute  
  query = query % db.literal(args)  
  TypeError: not enough arguments for format string  
  </code></pre>
  
  <p>EDIT: in case it helps, i'm using mysqldb version 1.2.3, in case it didn't accept tuples at that version, but don't get me started on how rubbish the mysqldb docs are..</p>