Another small DBD::Pg issue

lachoy on 2005-10-17T14:28:12

I bumped into another DBD::Pg issue posting that last news item, complaining about an unbound placeholder. That's straightforward enough, but in the SQL dumped to the error message there were no placeholders! A closer inspection showed that the dates weren't quoted -- ouch. (SPOPS doesn't use bound placeholders for inserts, instead quoting each value it passes in. I think this was because n years ago DBD::Sybase didn't properly bind TEXT datatypes but I'm not sure.)

Anyway, a little investigation showed that the two-argument quote() method implemented by DBD::Pg does not quote dates properly. The two-argument version takes both the value to be quoted along with the field's datatype ('93' as reported by DBD::Pg for a timestamp field). The one-arg version is fine, though, since it just blindly escapes and quotes whatever you give it.

So the workaround was pretty easy: in SPOPS::DBI::Pg I just had to override the sql_quote() method from SPOPS::SQLInterface to use the one-arg form of DBI->quote() when given a timestamp datatype.

And yes, I created a quick test to show this and posted it to its RT queue like a good open source citizen.

Posted from cwinters.com; read original