Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: Class::DBI::AbstractSearch and SpeedyCGI

by zigdon (Deacon)
on Oct 04, 2005 at 10:55 UTC ( #497195=note: print w/replies, xml ) Need Help??

in reply to Re: Class::DBI::AbstractSearch and SpeedyCGI
in thread Class::DBI::AbstractSearch and SpeedyCGI

The reason I thought it was the bind variable is that that's the only array I can see involved in this query - see the code below. The stack, afaik, is something like this:
MyApp::Sets: my @res = Peeron2::Sets->search_where({ID => "8880-1"}); Class::DBI::AbstractSearch->search_where: return $class->retrieve_from_sql("( id = ? )", "8880-1"); # Class::DBI->retrieve_from_sql: $class->sth_to_objects($class->sql_Retrieve("id = ?")), ["8880-1"]); Class::DBI->sth_to_objects: $sth->execute("8880-1") unless $sth->{Active};
Here's the relevant lines in the PMs. Class::DBI::AbstractSearch:
sub search_where { my $class = shift; my $where = (ref $_[0]) ? $_[0] : { @_ }; my $attr = (ref $_[0]) ? $_[1] : undef; my $order = ($attr) ? delete($attr->{order_by}) : undef; # order is deprecated, but still backward compatible if ($attr && exists($attr->{order})) { $order = delete($attr->{order}); } $class->can('retrieve_from_sql') or do { require Carp; Carp::croak("$class should inherit from Class::DBI >= 0.90"); }; my $sql = SQL::Abstract->new(%$attr); my($phrase, @bind) = $sql->where($where, $order); $phrase =~ s/^\s*WHERE\s*//i; return $class->retrieve_from_sql($phrase, @bind); # <------------- +--31 }
sub retrieve_from_sql { my ($class, $sql, @vals) = @_; $sql =~ s/^\s*(WHERE)\s*//i; return $class->sth_to_objects($class->sql_Retrieve($sql), \@va +ls); } ... sub sth_to_objects { my ($class, $sth, $args) = @_; $class->_croak("sth_to_objects needs a statement handle") unle +ss $sth; unless (UNIVERSAL::isa($sth => "DBI::st")) { my $meth = "sql_$sth"; $sth = $class->$meth(); } my (%data, @rows); eval { $sth->execute(@$args) unless $sth->{Active}; # <------ +--------- 1124 $sth->bind_columns(\(@data{ @{ $sth->{NAME_lc} } })); push @rows, {%data} while $sth->fetch; }; return $class->_croak("$class can't $sth->{Statement}: $@", er +r => $@) if $@; return $class->_ids_to_objects(\@rows); }

-- zigdon

Replies are listed 'Best First'.
Re^3: Class::DBI::AbstractSearch and SpeedyCGI
by zigdon (Deacon) on Oct 04, 2005 at 11:14 UTC
    I just tried to add a
    warn Dumper $args;
    right before the ->execute line... When everything works, it returns what you'd expect ( [ "8880-1" ] ), but when it dies, it didn't output anything? This is just messing me up!

    -- zigdon

      I'm guessing that your ID is sometimes undef in your call to search_where(). You might have a bug with the way you are reading this param from CGI, maybe involving a closure.
        All the debugging code I put in never showed a called with an undef for the ID... But even if it was there, it doesn't seem to bomb:
        @r = MyApp::Sets->search_where(ID => undef); print Dumper \@r __OUTPUT__ $VAR1 = [];
        Which is what it should do - return an empty set when the search returns nothing... For now, I've modified Speedy to exit after a single run - this means that I still run my script from the compiled version, but not persistantly. Seems to work around the problem, but of course, not ideal. Any other ideas what I should be looking at? Thanks for all the suggestions so far!

        -- zigdon

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://497195]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2019-05-24 18:01 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (151 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!