Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can't replicate this with MySQLdb. I'm using 1.2.2 final. Perhaps try a simple debug, to be sure that the problem is where you have indicated:</p> <pre><code>In [13]: cur.execute('select %s + %s', (1,2)) Out[13]: 1L In [14]: cur.fetchall() Out[14]: ((3L,),) </code></pre> <p>UPDATE 1: So I grabbed and installed 1.2.3 final, here's my transcript: </p> <pre><code>In [1]: import MySQLdb In [2]: MySQLdb.version_info Out[2]: (1, 2, 3, 'final', 0) In [3]: con = MySQLdb.connect(user='root', db='inventory') In [4]: cur = con.cursor() In [5]: cur.execute('select %s + %s', (1,2)) Out[5]: 1L In [6]: cur.fetchall() Out[6]: ((3L,),) </code></pre> <p>If only I could replicate your problem, then maybe I'd be able to offer a solution!? So what else is different between our two environments? </p> <pre><code>$ mysql --version mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (x86_64) using readline 6.1 </code></pre> <p>UPDATE 2: You can perhaps break things down a little more than above. Note the following snippet from the source for MySQLdb-1.2.3: </p> <pre><code>139 def execute(self, query, args=None): ... 158 if args is not None: 159 query = query % db.literal(args) 160 try: 161 r = self._query(query) 162 except TypeError, m: 163 if m.args[0] in ("not enough arguments for format string", 164 "not all arguments converted"): 165 self.messages.append((ProgrammingError, m.args[0])) </code></pre> <p>line 159 is where your args are converted/escaped and then inserted into the query string. So perhaps you could do something like this: </p> <pre><code>In [24]: con.literal((1,2,)) Out[24]: ('1', '2') </code></pre> <p>To see how arguments are being converted by the driver, prior to merging with your query string. </p> <pre><code>In [26]: "select %s + %s" % con.literal((1,2,)) Out[26]: 'select 1 + 2' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload