[Dbix-class] binding variables to CASE WHEN

Peter Rabbitson rabbit+dbic at rabbit.us
Wed Apr 8 20:50:40 GMT 2015


On 04/08/2015 10:44 PM, Dagfinn Ilmari Mannsåker wrote:
> 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.

It's not even "in the front". It is specifically "in front of the FROM 
bind stack". There is a separate SELECT bind stack (for 'select' => 
\['foo + ?', 42]) and even a pre-SELECT bind stack (for things like 
https://metacpan.org/pod/DBIx::Class::SQLMaker::LimitDialects#SkipFirst)





More information about the DBIx-Class mailing list