像这样:
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}]
为什么结果不一样?
最佳答案
这是因为 MySQLdb 驱动程序将查询参数插入到查询中的方式。
第一个查询实际上转化为(看引号):
select 'id' from topic order by 'id desc' limit 2
'id'
这里是字符串,不是列名。
关于python - torndb(MySQLdb) 查询参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27361832/