[Dbix-class] "having" attribute problems with SQLite

Matt S Trout dbix-class at trout.me.uk
Fri Aug 8 02:40:42 BST 2008


On Tue, Aug 05, 2008 at 12:38:46AM +0100, Will Hawes wrote:
> The 0.08010 docs in DBIx::Class::ResultSet contain an example for the
> "having" attribute that shows parameter values being passed using a
> hashref:
> 
> having => { 'count(employee)' => { '>=', 100 } }
> 
> Meanwhile, in the test suite there are a couple of tests using
> "having" (76joins.t in 0.08010 and 77prefetch.t in 0.08 trunk), but
> these both pass a scalar ref instead, like this:
> 
> $rs = $rs->search( undef, {  having =>{ 'count(*)'=> \'> 2' }});
> 
> DBIC_TRACE shows the following SQL is generated for the above test:
> 
> SELECT me.artistid, me.name FROM artist me LEFT JOIN cd cds ON (
> cds.artist = me.artistid ) GROUP BY me.name HAVING ( ( ( MAX(cds.cdid)
> < 5 ) AND ( count(*) > 2 ) ) ):
> 
> And here's what happens if the test is altered to use the hashref syntax:
> 
> $rs = $rs->search( undef, {  having =>{ 'count(*)'=> { '>', 2' }}});
> 
> SELECT me.artistid, me.name FROM artist me LEFT JOIN cd cds ON (
> cds.artist = me.artistid ) GROUP BY me.name HAVING ( ( ( MAX(cds.cdid)
> < 5 ) AND ( count(*) > ? ) ) ): '2'
> 
> Both look fine to me and I'm not getting any errors, but I'm seeing
> the scalarref syntax return rows as expected, while the hashref syntax
> returns zero rows irrespective of what's in the database.
> 
> I've observed this on two machines, one running DBD::SQLite 1.14 and
> DBI 1.607 and the other DBD::SQLite 1.13 and DBI 1.57.
> 
> I don't have a database server handy to test against other drivers
> atm, but since DBIx::Class::Storage::DBI calls $sth->bind_param when
> the hashref syntax is used I'm guessing the DBIC docs are correct and
> that this may be a DBD problem of some sort.
> 
> I've not found reference to anything similar in the list archives -
> can anyone else confirm this behaviour before I go any further?

Never seen it in my life. I'd be writing a plain DBI script to check it
and then running that against other DBs.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list