Thanks, I tried that, it makes the query right, but when I access the
result in a for loop it gives now:
'Cursor' object has no attribute '_last_executed'
Think for now I just stay with using 2 variables, that works fine for
the moment.
Am 17.11.2013 00:38, schrieb Dennis Lee Bieber:
> On Sat, 16 Nov 2013 22:39:09 +0100, Thorsten Sanders
> <
thorsten...@gmx.net> declaimed the following:
> I suspect the main problem is that you need to set up the realms
> parameter differently -- along with the query string.
>
> MySQL, and most other SQL systems, as I recall, expect to see
>
> ... needle in (first, second, ..., last)
>
> MySQLdb sanitizes parameters by converting them to a string
> representation, escaping any special characters, and wrapping it is '
> marks.
>
> In the raw query, unless Django has an SQL parser, the above is
> generating
>
> select * from auctiondata_auctiondata where itemid_id = 'something' and
> realm_id in '[1]'
>
> when what you need to generate is
>
> select * from auctiondata_auctiondata where itemid_id = 'something' and
> realm_id in ('1')
>
> (MySQLdb doesn't know what datatype to put in at each %s -- it has first
> converted all inputs into safe strings; that's why it uses %s for the
> placeholder).
>
> If using a list of values, you'll have to create an SQL format with a
> %s for EACH value, not the list
>
> SQL = " ...%%s and stuff in (%s)" % ", ".join("%s" for x in realms)
> (if realms is [1, 3, 99] this creates
> SQL ="... %s stuff in (%s, %s, %s" )
>
> You then need to flatten the parameters
>
> parms=[itemid].extend(realms)
>