2 ms·
1) dynamically adjust the number of parameters in your prepared statement params = ", ".join(["?"] * count) template = "SELECT ... WHERE foo in (%s)" % (pa
by andor 6y ago
1) dynamically adjust the number of parameters in your prepared statement
params = ", ".join(["?"] * count)
template = "SELECT ... WHERE foo in (%s)" % (params)
# proceed to prepare a statement from the query template
2) use a subquery, insert data somewhere if necessary
SELECT ... WHERE foo in (SELECT foo FROM foos WHERE some_value = 42)
3) if the maximum number of parameters is low, you can keep it variable by enabling parts of the query with boolean parameters:
SELECT ... WHERE (test_param1 AND foo = param1)
OR (test_param2 AND foo = param2)
OR (test_param3 AND foo = param3)