Python SQL排序在字符串格式中不起作用
我有一个sql,它可以工作:Python SQL排序在字符串格式中不起作用,python,sql,sql-order-by,Python,Sql,Sql Order By,我有一个sql,它可以工作: cursor.execute('select * from video_title_difference where title like %s order by provider desc limit %s offset %s', ('%' + search + '%', limit, offset)) 但是如果我将ORDER BY变量(即现在的“提供者”)更改为变量,则它根本不起作用: cur
cursor.execute('select * from video_title_difference where title like
%s order by provider desc limit %s offset %s',
('%' + search + '%', limit, offset))
但是如果我将ORDER BY变量(即现在的“提供者”)更改为变量,则它根本不起作用:
cursor.execute('select * from video_title_difference where title like %s
order by %s limit %s offset %s',
('%' + search + '%', order_by, limit, offset))
它“有效”,但它根本不订购。我做错了什么?问题是您试图将表设置为参数 表名不能参数化 我的方法是在代码中硬编码表名,您需要了解使用表名可能会导致安全问题,特别是当它来自用户时 我将添加一些关于此问题的帖子: ,,