I am using the python sqlite3 package to execute queries. To avoid the sql injection issues I am using placeholders for the input parameters. In my case the order by column is also coming from an input parameter.
So I wrote my code as below:
column = 'somecolumn'
query= "select name from MyTable where id = ? Order by ?"
params = (id , column)
cur = conn.cursor()
cur.execute(query,params)
The placeholder substitution did not work for sql keyword Order by. Is there any way that I can make this work without having to worry about sql injections?
Thanks, Gaurav