Wee
Wee

Reputation: 232

torndb(MySQLdb) query params not work

Like this:

In [43]: conn.query('select %s from topic order by %s limit 2', 'id', 'id desc')
Out[43]: [{'id': u'id'}, {'id': u'id'}]
In [44]: conn.query('select id from topic order by id desc limit 2')
Out[44]: [{'id': 10L}, {'id': 9L}]

Why the result is not the same?

Upvotes: 1

Views: 248

Answers (1)

alecxe
alecxe

Reputation: 474141

This is because of the way query parameters are inserted into the query by the MySQLdb driver.

The first query is actually transformed into (watch the quotes):

select 'id' from topic order by 'id desc' limit 2

'id' here is a string, not the column name.

Upvotes: 1

Related Questions