I'm looking to create a function that generates an SQL query, filtering the results by an expression given as a parameter (which will passed as a 'WHERE' clause). If the parameter is omitted, all results are returned.
In order to do this I can test for a null parameter and only build the where clause if parameter is given (where = (parameter != null) ? "" : "WHERE " + parameter
). However, I was thinking is there an expression that I can default to that will always return all results. This way I don't need to test to see whether to include the WHERE
keyword (where = "WHERE " + parameter
).
I've intentionally not mentioned escaping the parameter to avoid injection. I won't forget this in my solution, I promise! :)