[Rt-devel] [PATCH] DBIx-SB: _LoadFromSQL fix&cleanups
Ruslan U. Zakirov
Ruslan.Zakirov at miet.ru
Sun May 22 06:29:11 EDT 2005
Hello, all.
Here is new patch for trunk(applies with shift). Patch fixes issues in
_LoadFromSQL method, tests that cover this issues I sent in previous mail.
Changes:
_LoadFromSQL never reported error when PK fields are missed. Fixed.
fetchrow_hashref dies only when RaiseErrors is true, because we can
control this from Handle obj so we should die according to
$Handle->RaiseErrors property. Fixed.
When RaiseErrors is "false" then fetchrow_hashref returns undef and we
should check $sth->err(see `perldoc DBI`). Fixed.
After call to fetchrow we should clean "fetched" internal hash and fill
it only when we return successful result. Fixed.
If SimpleQuery fails, _LoadFromSQL method doesn't return any error
message. Fixed.
--
Best regards, Ruslan.
-------------- next part --------------
=== SearchBuilder/Record.pm
==================================================================
--- SearchBuilder/Record.pm (revision 1655)
+++ SearchBuilder/Record.pm (local)
@@ -1096,31 +1096,28 @@
#TODO this only gets the first row. we should check if there are more.
- unless ($sth) {
- return($sth);
- }
+ return ( 0, "Couldn't execute query" ) unless $sth;
- eval { $self->{'values'} = $sth->fetchrow_hashref; };
- if ($@) {
- warn $@;
+ $self->{'values'} = $sth->fetchrow_hashref;
+ $self->{'fetched'} = {};
+ if ( !$self->{'values'} && $sth->err ) {
+ return ( 0, "Couldn't fetch row: ". $sth->err );
}
unless ( $self->{'values'} ) {
return ( 0, "Couldn't find row" );
}
-
- foreach my $f ( keys %{$self->{'values'}||{}} ) {
- $self->{'fetched'}{lc $f} = 1;
- }
-
## I guess to be consistant with the old code, make sure the primary
## keys exist.
- eval { $self->PrimaryKeys(); };
- if ($@) {
- return ( 0, "Missing a primary key?: $@" );
+ if( grep { not defined } $self->PrimaryKeys ) {
+ return ( 0, "Missing a primary key?" );
}
+
+ foreach my $f ( keys %{$self->{'values'}} ) {
+ $self->{'fetched'}{lc $f} = 1;
+ }
return ( 1, "Found Object" );
}
More information about the Rt-devel
mailing list