[Dbix-class] Re: Creating custom resultset error and MySQL

Marcello Romani mromani at ottotecnica.com
Mon Jul 14 07:56:15 BST 2008


Andreas Pronakis ha scritto:
> I will have to apologise for being 'hasty'.
> 
> The SQL is fine (the 'me' is actually there, I was just assuming it was part of the {bin} params because it was appearing on the next line with :$value in DBIC_TRACE), so that's fine.
> 
> However, the error remains, where I get an empty arrayref as the result even though the database has values for the SQL.
> 
> Further investigation revealed that:
> 1. I can only get a custom SQL to work only if I do not use the PRIMARY_KEY as part of the WHERE clause.  I haven't fully investigated this, but if I change the WHERE to any other column, I get back a ResultSet.
> 
> 2. Following on thr last sentence from point 1 - I do not need to call the custom ResultSet within an arrayref i.e.
> $story_obj = $schema->resultset('FindStory')->search({}, { bind => [$value]});
> 
> is working fine (returns a ResultSet) - notice the missing [...] around the call.  Is this something that was changed resentrly but not updated in the Cookbook docs or something else?
> 
> 

 From my experience, search() reacts to the calling context as follows:

if you call search() within a listref, i.e. between brackets, then it's 
  executed in list context, therefore it doesn't return a resultset, it 
returns an array containing all the objects (rows) produced by the sql 
query.

If you call search() in scalar context, instead, it returns a ResultSet 
from which you can obtain the same objects one by one via next() or all 
at once by calling ->all() in list context ( my @objects = $rs->all() ).

HTH

-- 
Marcello Romani
Responsabile IT
Ottotecnica s.r.l.
http://www.ottotecnica.com



More information about the DBIx-Class mailing list