[Dbix-class] Removing quote chars from HAVING terms?

Chris Burch cburch at madison.k12.wi.us
Wed Apr 15 14:28:53 GMT 2009


>>>> 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?

Thanks,
Chris



Chris Burch
Data Analyst/Web Programmer
Planning/Research & Evaluation
Madison Metropolitan School District
(608) 663-1916
cburch at madison.k12.wi.us
 





More information about the DBIx-Class mailing list