ar0n has asked for the wisdom of the Perl Monks concerning the following question:
I'm having some difficulties tracking down a problem with DBI. I have a method called get_picture which pulls out data from a MySQL database and returns a set of objects.
The method get_picture can be called with a column name/value pair to narrow the results, e.g:
my @pics = $db->get_pictures( user => 83, category => 9 );
And it worked fine up until today, when I added two columns to the select query, width and height. The width and height columns were part of the picture table for while, but I hadn't a need for them up until now.
Whereas before $db->get_picture( user => 1 ) would return four Phab::Picture objects, it now returns none. And the weird thing is, it does work if I remove the width and height columns from $sql and the $get->bind_columns call.
The complete get_picture method is below.
Any ideas?
sub get_picture { my $self = shift; my %clauses = @_; my (@pictures, @params); my ($id, $user, $created, $title, $caption); my ($type, $category, $filename, $size); my ($width, $height); my $sql = " SELECT id, user, created, title, caption, category, type, filename, size, width, height FROM picture"; if (%clauses) { $sql .= " WHERE " . join " AND ", map { "$_ = ?" } sort keys %clau +ses; @params = map { $clauses{$_} } sort keys %clauses; } my $get = $self->dbh->prepare($sql); $get->execute(@params); $get->bind_columns( \( $id, $user, $created, $title, $caption, $category, $type, $filename, $size, $width, $height ) ); while ($get->fetchrow) { my $picture = new Phab::Picture ( id => $id, user => $user, created => $created, title => $title, caption => $caption, type => $self->get_type( id => $type ), category => $self->get_category( id => $category ), filename => $filename || "unknown", size => $size, width => $width || 0, height => $height || 0 ); push @pictures, $picture; } return wantarray ? @pictures : $pictures[0]; }
[ ar0n -- want job (boston) ]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Disappearing results with DBI and bind_columns
by lachoy (Parson) on Dec 31, 2001 at 04:08 UTC | |
by ar0n (Priest) on Dec 31, 2001 at 04:30 UTC | |
by steves (Curate) on Dec 31, 2001 at 10:42 UTC | |
(Ovid) Re: Disappearing results with DBI and bind_columns
by Ovid (Cardinal) on Dec 31, 2001 at 04:10 UTC | |
by ar0n (Priest) on Dec 31, 2001 at 04:21 UTC | |
Re: Disappearing results with DBI and bind_columns
by petdance (Parson) on Dec 31, 2001 at 04:11 UTC |