4 ms·
As a side note, it's not always possible to use parameter binding for all parts of a SQL query. :( For example, when querying user uploaded databases (not a ty
by justinclift 10y ago
As a side note, it's not always possible to use parameter binding for all parts of a SQL query. :(
For example, when querying user uploaded databases (not a typical use case), the SQL query needs to include the table name. At least with SQLite (unsure about PostgreSQL), table names can't be bound in a parameter. They need to be part of the non parameterised query string, thus string smashing.
Field/column names are probably similar too, though I haven't checked (yet).
- koolba 10y agoIf you're doing anything that esoteric hopefully you understand proper identifier escaping. If not, there's bound to be much worse throughout your app.
- snuxoll 10y agoThat's what libraries like sequel, SQLAlchemy or Jooq are for. I'm looking at implementing some crazy dynamic queries in a CRM system I'm prototyping right now and SQLAlchemy is my saving grace to avoid shooting myself in the foot.
- true_religion 10y agoThat's true, but an ORM like ActiveRecord ought to protect you from this because you are required to specify valid column names and table names before using it. It should be able to check if an invalid column or table name is used.