[Rt-commit] r2906 - in DBIx-SearchBuilder/trunk: . SearchBuilder

jesse at bestpractical.com jesse at bestpractical.com
Sun May 22 15:25:21 EDT 2005


Author: jesse
Date: Sun May 22 15:25:21 2005
New Revision: 2906

Modified:
   DBIx-SearchBuilder/trunk/   (props changed)
   DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm
Log:
 r16976 at hualien:  jesse | 2005-05-22 15:18:08 -0400
 _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.     
 
 
         - Ruslan
 


Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm	Sun May 22 15:25:21 2005
@@ -1096,30 +1096,27 @@
 
     #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-commit mailing list