I have a filter object to query a table with many columns and instead of writing a condition that spans all columns (allowing for additional filtering), like this:
WHERE ((:value0 IS NULL) OR (column_name0 = :value0)) AND ((:value1 IS NULL) OR (column_name1 = :value1)) AND... etc
for each column. Instead, I would ideally want to pass the field name as a parameter:
WHERE :column_name0 = :value0 AND column_name1 = :value1 AND... etc
which is not possible since columns are required during parsing (similar to this answer given here ).
How do you overcome this? . I really do not want to support SQL when new columns are added or removed (as in the first example), and I think it would be dangerous for me to build the column names on the command line directly, as this could allow SQL injection.
Please note that this code is behind the web service.
Mr shoubs
source share