A particular irritant is that most (all?) db APIs make it impossible to use parametrized queries with IN clauses. I find myself having to implement string escaping functions sooner or later in every project, because of stuff like that.
sql = '... col_name IN ('
foreach(var arg in args)
if (!first)
sql.append(', ')
sql.append('?')
params.add(arg)
sql.append(')')Psycopg2 has a generic adaptation of iterables to a form suitable for IN, but it's hand-rolled: https://github.com/psycopg/psycopg2/blob/732ea90a4ff85f6d0cc...
Real convenient though.
Our current solution is to use of temporary table because other solutions (including dynamically adding parameter in query) makes them unique queries and crashes performance.
I believe at one point IN (values) was just sugar for = ANY(ARRAY(values)), don't know if that's still the case.
Still requires that your DB adapter supports array parameters though.
I really don't get why anyone in this day and age doesn't use parameterised queries.
It's such a big security win and comes with such little programming overhead that it boggles my mind to think people still use manual string escaping.
And the most recent LTS, 16.04, has 9.5.
[1] http://blog.endpoint.com/2014/04/custom-plans-prepared-state...
People care more about convenience and fast iteration than security - concatenation is faster and easier, and insecure sites can still make money, so the incentives are on the side of fast, dirty code that works now rather than secure code that works later.
People (this is especially true in the PHP world) may not even know parameterized queries exist.
I see this sort of thing on a daily basis, but it's not from PHP developers but our "lead" Delphi developer. I've tried to convince him of the benefits of parameter based queries, but believes that it would be a performance hit (performance for him maybe, he'd have to struggle to learn something new).