title: Inserting a python variable into a query
body: <p>I'm trying to pull back a fairly involved query from mysql - I've got the connection working OK, and can successfully complete the query when I hard code the values. </p>
  
  <p>I'd like to make one of the values a python variable - I am following the method I found here: <a href="https://stackoverflow.com/questions/902408/how-to-use-variables-in-sql-statement-in-python">How to use variables in SQL statement in Python?</a> as the listed usecase seems pretty much the same as mine. </p>
  
  <p>The mysql execute function I am using is different to the solved problem, and I can't figure out where to place the python variable into the execute call. </p>
  
  <p>My code:</p>
  
  <pre><code>targetPUID = "fmt/123"
  
  cur.execute("""
  (
  SELECT `PUID`,`DROID_V`,`SIG_V`,`SPEED`,
  COUNT(distinct IF(sourcelist.hasExtension=1,NAME,NULL)) as Ext,
  COUNT(distinct IF(sourcelist.hasExtension=0,NAME,NULL)) as NoExt,
  COUNT(distinct NAME) as `All`
  FROM sourcelist, main_small
  WHERE sourcelist.SourcePUID ="%s" AND main_small.NAME = sourcelist.SourceFileName
  GROUP BY `PUID`,`DROID_V`,`SIG_V`,`SPEED` ORDER BY `DROID_V` ASC, `SIG_V`
   )
  """) 
  </code></pre>
  
  <p>I know I need to place a reference to my variable <code>targetPUID</code>to link up with the <code>%s</code> in the query. </p>
  
  <p>___________________FIXED___________________</p>
  
  <p>OK, got it working:</p>
  
  <pre><code> cur.execute("""
   (
   SELECT `PUID`,`DROID_V`,`SIG_V`,`SPEED`,
   COUNT(distinct IF(sourcelist.hasExtension=1,NAME,NULL)) as Ext,
   COUNT(distinct IF(sourcelist.hasExtension=0,NAME,NULL)) as NoExt,
   COUNT(distinct NAME) as `All`
   FROM sourcelist, main_small
   WHERE sourcelist.SourcePUID =%s AND main_small.NAME = sourcelist.SourceFileName
   GROUP BY `PUID`,`DROID_V`,`SIG_V`,`SPEED` ORDER BY `DROID_V` ASC, `SIG_V`
   )
  """,targetPUID)
  </code></pre>
  
  <p>and </p>
  
  <pre><code> targetPUID = "x-fmt/409"
  </code></pre>
  
  <p>I don't have enough rep to add the fix yet. Thanks for reading. </p>