[Dbix-class] binding variables to CASE WHEN
Dagfinn Ilmari Mannsåker
ilmari at ilmari.org
Wed Apr 8 20:44:40 GMT 2015
Augustus Saunders <asaunders at solfo.com> writes:
> Outside of count, here is an example that messes up:
>
> 'attrs' => {
> 'select' => [
> \[
> 'aggfunction(col, ?)',
> 'somevar'
> ]
> ],
> 'group_by' => 'somecolumn1',
> 'having' => {
> '-and' => [
> {
> 'aggfunction(col, ?)' => {'>' => '0'}
> }
> ]
> }
> 'bind' => [
> 'somevar'
> ],
> },
> 'where' => {
> '-and' => [
> {
> 'somecolumn2' => 1
> }
> ]
> }
>
> The 'somevar' that comes from bind => ['somevar'] is not being
> correctly lined up with the unbound ? from the having clause. At the
> DBI level we bind_param(1,somevar), bind_param(2, somevar),
> bind_param(3, 1), bind_param(4, 0), but the order should go somevar,
> 1, somevar, 0.
Well, DBIC can't possibly know which part the bind parameter goes with,
so as Peter explained it just sticks it at the front. Also, having an
expression on the LHS of the hash will break if you enable quote_names.
Instead, just do:
having => \['aggfunction(col, ?) > ?', 'somevar', 0],
and it'll go in the right place reliably.
--
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
the consequences of." -- Skud's Meta-Law
More information about the DBIx-Class
mailing list