[Dbix-class] Removing quote chars from HAVING terms?
Peter Rabbitson
rabbit+dbic at rabbit.us
Wed Apr 15 14:54:04 GMT 2009
Chris Burch wrote:
>>>>> Peter Rabbitson <rabbit+dbic at rabbit.us> 4/15/2009 3:37 AM >>>
>> Ben Vinnerd wrote:
>>> Ben Vinnerd wrote:
>>>> Have you tried...
>>>>
>>>> having => \"count(me.[sectionid]) = $section_ct",
>>>
>>> You would also have to make sure $section_ct is properly quoted of
>>> course :)
>>>
>
>> No you wouldn't. Instead you would do:
>
>> having => \"count(me.[sectionid]) = ?,
>> bind => [ $section_ct ],
>
>> Now to be fair it seems that the bind parameter is not documented
>> anywhere. Patches to ResutSet.pm welcome.
>
>
> Unfortunately that doesn't work for me using 0.08013. Here is my ResultSet, in Catalyst:
>
> my $task_rs = $c->model('Warehouse::Tasks')->search(
> {
> termid => $c->session->{termid},
> sectionid => $c->session->{sections},
> },
> {
> columns => [ qw/taskid taskname/ ],
> group_by => [qw/me.taskid me.taskname/],
> having => \"count(me.[sectionid]) = ?",
> bind => [ $section_ct ],
> }
> );
>
>
> Here is what DBIC_TRACE spits out:
>
> SELECT [me].[taskid], [me].[taskname] FROM [webapps].[vOpenGradingTasks] [me] WHERE ( ( ( [sectionid] = ? OR [sectionid] = ? ) AND [termid] = ? ) ) GROUP BY [me].[taskid], [me].[taskname] HAVING count(me.[sectionid]) = ?: '2', '474945', '474944', '924'
>
> ... as you can see, the bound parameter is used first and I want it used last. Am I writing the search incorrectly / inefficiently?
>
No, you just can't mix custom bind attributes with SQLA where
conditions. We should probably start warning/die()ing on such usage.
What you want is to chain:
$rs->search ( { your cond}, { other attrs} )
->search ({}, { having..., bind... }) <-- note the empty {}
More information about the DBIx-Class
mailing list