-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Tim Bunce wrote:

> For code not using DBIx::Class the pg_placeholder_dollaronly attribute
> might work, see https://metacpan.org/pod/DBD::Pg#Placeholders

Yes, this is the current canonical solution. It's a real shame 
that ? was used as an operator, but that horse has left the barn.

> For code using DBIx::Class the problem is more tricky. I'm pretty sure
> that SQL::Abstract and thus DBIx::Class only support question mark
> placeholders. That means it probably impossible to use expressions
> containing a question mark operator with SQL::Abstract/DBIx::Class.
> (Though I'd be delighted to be proven wrong.)
> 
> So I think the DBI spec for placeholders needs to be extended to allow a
> way to 'escape' a question mark that the driver would otherwise treat as
> a placeholder.
>
> The obvious and natural approach would be to use a backslash before a
> question mark. The backslash would be removed by the driver before the
> statement is passed to the backend.

I'm going to play devil's advocate a bit here. There are some problems with 
this approach. First, it will require that the user know if the underlying 
DBD supports backslashes. Which likely means that SQL::Abstract and/or 
DBIx::Class will need to know as well. (Unless they expose the DBD directly 
to the user, which ruins the point a bit). Since we will thus need to patch 
those other modules, so why not fix them to do the right thing? (see below 
for a counter proposal).

Another problem is that we have now extended the SQL syntax for our own 
purposes. While one could argue that placeholders already do so, their 
current use is consistent, widespread (e.g. not just DBI), and in part 
used by the underlying RDBMSs themselves (e.g. Postgres uses dollar-number 
placeholders). So we will have both escaped and unescaped versions of SQL 
floating around, subject to the whims of whether or not your particular 
DBD supports it (and in which version). All of which seems like an awful 
lot of work to "fix" SQL::Abstract. Why bother patching every DBD in 
existence when we can simply patch SQL::Abstract?

Which leads to my counter-proposal: have SQL::Abstract accept dollar-number 
placeholders. It can pass pg_placeholder_dollaronly down the stack as 
needed. This neatly puts the onus back onto the frameworks, rather than 
having the DBDs selectively remove backslashes before passing to the 
RDBMS (ick). DBIx::Class and friends could even map dollar signs back to 
a format supported by the underlying DBDs, if they don't support dollar 
signs (that is one of their grand purposes after all - abstracting out 
details and taking care of things in the background).

- -- 
Greg Sabino Mullane g...@turnstep.com
PGP Key: 0x14964AC8 201412211008
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAlSW5E8ACgkQvJuQZxSWSshusgCfXOIjbJxQAF9s7FJEncDFoBGG
oHgAnjMs9kP/imrZTnknJpUIuXOhmoPL
=FxZ4
-----END PGP SIGNATURE-----


Reply via email to