Reputation: 3039
In webpy db module I have a query:
db().query("select * from table where column in ($ERROR_LIST)",
vars=dict(ERROR_LIST=ERROR_LIST)).list()
There is no issue with this query if the ERROR_LIST
is just a variable. But my requirement is that the ERROR_LIST
must be list of error values. Is there a way to handle list in webpy DB module or is there any other way to do the job?
Upvotes: 2
Views: 533
Reputation: 26
If you have a variable error_list
that holds a list of the values, let webpy convert everything for you and don't add the () arround the variable either:
db.query("SELECT * FROM table WHERE column IN $ERROR_LIST", vars(dict(ERROR_LIST,error_list)))
Since I believe reparam
uses the same methods, this seems to work (including adding parenthesis for you):
>>> error_list = ['a','b','c']
>>> reparam("s IN $ERROR_LIST", dict(ERROR_LIST=error_list))
<sql: "s IN ('a', 'b', 'c')">
Upvotes: 1