<div class="gmail_quote">On Fri, May 28, 2010 at 2:17 AM, Dennis Lee Bieber <span dir="ltr"><<a href="mailto:wlfraed@ix.netcom.com">wlfraed@ix.netcom.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
On Thu, 27 May 2010 23:22:24 +0100, MRAB <<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>><br>
<div class="im">declaimed the following in gmane.comp.python.general:<br>
<br>
><br>
</div><div class="im">> Placeholders which are handled by .execute shouldn't be wrapped in<br>
> quotes, even is the value is a string, because .execute will handle that<br>
> (and any other details) itself.<br>
<br>
</div>        Even more internal details -- the MySQLdb placeholder is %s because<br>
the adapter, internally, converts ALL parameters to strings, applies<br>
escapes to them, and THEN wraps them with quotes before using Python<br>
string interpolation to make the query that gets submitted to the<br>
server.<br>
<br>
        This is why you can not use, say %d as a placeholder for a numeric<br>
parameter... MySQLdb will convert that numeric to a string, and then<br>
Python will choke when it tries to use a %d formatter and is given a<br>
string value.<br>
<div class="im"><br><br></div></blockquote><div>All of your and MRAB's comments were very helpful. However, I don't see how these two problems are addressed:<br><br>      sql = 'select * from options%s where 
ID=%%s', (opTable[0].upper() + opTable[1:])<br>#      
cursor.execute(sql, id)<br>      cursor.execute('select * from options%s
 where ID=%s' % (opTable[0].upper() + opTable[1:], id))<br>
<br>The last one works, but if I comment it out and uncomment the middle
 line, it doesn't. Same here:<br><br>        sql = "update options%s set
 PriceDiff='%%s' where Field='%%s' and ID=%%s and Store='%%s'" % 
(opTable[0].upper() + opTable[1:])<br>
#        cursor.execute(sql, (value, opName, id, store))<br>        
cursor.execute('update options%s set PriceDiff="%s" where Field="%s" and
 ID=%s and Store="%s"' % (opTable[0].upper() + opTable[1:], value, 
opName, id, store))<br>
<br>TIA,<br>beno<br> </div></div><br>