News for hackers. Stuff that matters.
Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by paol on Sunday June 26, 2016 @06:44AM (#11980221)
This is absolutely good advice, but people giving it rarely acknowledge that it isn't always possible.

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.

Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by tbrownaw on Sunday June 26, 2016 @11:38AM (#11981217)
That's when you combine parameterized queries and concatenated SQL:

    sql = '... col_name IN ('
    foreach(var arg in args)
      if (!first)
        sql.append(', ')
      sql.append('?')
      params.add(arg)
    sql.append(')')
Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by masklinn on Sunday June 26, 2016 @09:06AM (#11980599)
> A particular irritant is that most (all?) db APIs make it impossible to use parametrized queries with IN clauses

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.

Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by tmd83 on Sunday June 26, 2016 @07:13AM (#11980301)
This is such an irritant. Everyone supports variable size IN clause in the form of a sub-select AFAIK. You should be able to abstract the parsing and have an api to address that. Yet for years its missing and you end up all sorts of garbage under-performing code.

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.

Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by icebraining on Sunday June 26, 2016 @07:34AM (#11980365)
At least in Postgres, you can use ANY and pass an array of values. From what I've read, the generated query plan is equivalent.
Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by masklinn on Sunday June 26, 2016 @09:11AM (#11980609)
> From what I've read, the generated query plan is equivalent.

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.

Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by snuxoll on Sunday June 26, 2016 @12:05PM (#11981340)
Alternatively, you can use a temp table and a join. Not ideal, but still safe from injection and should have roughly the same overhead in the database.
Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by batbomb on Sunday June 26, 2016 @11:15AM (#11981121)
This isn't the case with oracle, MySQL, or hsqldb, at least when using jdbc. I believe it's also not true for SQLite and postgres.
Re:Using Multi-Byte Characters to Nullify SQL Injection Sani... by continuational on Sunday June 26, 2016 @07:40AM (#11980390)
select * from Person where email = any(?)