[Jifty-commit] r4047 - in Jifty-DBI/trunk: lib/Jifty/DBI

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Sep 6 14:31:06 EDT 2007


Author: jesse
Date: Thu Sep  6 14:30:59 2007
New Revision: 4047

Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm

Log:
 r67016 at pinglin:  jesse | 2007-09-06 14:30:00 -0400
 * Add support for non-lowercase column names


Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	Thu Sep  6 14:30:59 2007
@@ -196,7 +196,6 @@
     my $self = shift;
 
     my $query_string = $self->build_select_query();
-
     # If we're about to redo the search, we need an empty set of items
     delete $self->{'items'};
 
@@ -829,8 +828,7 @@
             if ref $self->{record_class};
     } elsif ( not $self->{record_class} ) {
         my $class = ref($self);
-        $class =~ s/Collection$//
-            or die "Can't guess record class from $class";
+         $class =~ s/(Collection|s)$// || die "Can't guess record class from $class";
         $self->{record_class} = $class;
     }
     return $self->{record_class};
@@ -973,11 +971,7 @@
         @_    # get the real argumentlist
     );
 
-    # We need to be passed a column and a value, at very least
-    croak "Must provide a column to limit"
-        unless defined $args{column};
-    croak "Must provide a value to limit to"
-        unless defined $args{value};
+
 
     # make passing in an object DTRT
     my $value_ref = ref( $args{value} );

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm	Thu Sep  6 14:30:59 2007
@@ -426,7 +426,7 @@
 sub add_column {
     my $self = shift;
     my $name = shift;
-    $name = lc $name;
+    #$name = lc $name;
     
     $self->COLUMNS->{$name} = Jifty::DBI::Column->new()
     unless exists $self->COLUMNS->{$name};
@@ -451,7 +451,7 @@
 
 sub column {
     my $self = shift;
-    my $name = lc( shift || '' );
+    my $name = ( shift || '' );
     my $col = $self->_columns_hashref;
     return undef unless $col && exists $col->{$name};
     return $col->{$name};
@@ -672,7 +672,7 @@
 sub __value {
     my $self        = shift;
 
-    my $column_name = lc(shift);
+    my $column_name = shift;
     # If the requested column is actually an alias for another, resolve it.
     my $column = $self->column($column_name);
     if  ($column   and defined $column->alias_for_column ) {
@@ -682,6 +682,7 @@
 
     return unless ($column);
 
+
     # In the default case of "yeah, we have a value", return it as
     # fast as we can.
     return   $self->{'values'}{$column_name}
@@ -697,8 +698,6 @@
             . " WHERE $pkey = ?";
         my $sth = $self->_handle->simple_query( $query_string, $id );
         my ($value) = eval { $sth->fetchrow_array() };
-        warn $@ if $@;
-
         $self->{'values'}{ $column_name }  = $value;
         $self->{'fetched'}{ $column_name } = 1;
     }
@@ -790,6 +789,7 @@
         @_
     );
 
+
     my $ret = Class::ReturnValue->new();
 
     my $column = $self->column( $args{'column'} );
@@ -815,17 +815,11 @@
     if ( $self->{'fetched'}{ $column->name }
         || !$self->{'decoded'}{ $column->name } )
     {
-        if ((      !defined $args{'value'}
-                && !defined $self->{'values'}{ $column->name }
-            )
-            || (   defined $args{'value'}
-                && defined $self->{'values'}{ $column->name }
-
+        if ((      !defined $args{'value'} && !defined $self->{'values'}{ $column->name })
+            || (   defined $args{'value'} && defined $self->{'values'}{ $column->name } 
                 # XXX: This is a bloody hack to stringify DateTime
                 # and other objects for compares
-                && $args{value}
-                . "" eq ""
-                . $self->{'values'}{ $column->name }
+                && $args{value} . "" eq "" . $self->{'values'}{ $column->name }
             )
             )
         {
@@ -834,6 +828,8 @@
         }
     }
 
+
+
     if ( my $sub = $column->validator ) {
         my ( $ok, $msg ) = $sub->( $self, $args{'value'} );
         unless ($ok) {
@@ -1020,12 +1016,15 @@
             $self = $class->new( handle => (delete $hashref->{'_handle'} || undef));
     }
     
+    $self->{values} = {};
+    #foreach my $f ( keys %$hashref ) { $self->{'fetched'}{  $f } = 1; }
+    foreach my $col (map {$_->name} $self->columns) {
+        next unless $hashref->{lc($col)};
+        $self->{'fetched'}{$col} = 1;
+        $self->{'values'}->{$col} = $hashref->{lc($col)};
 
-    foreach my $f ( keys %$hashref ) {
-        $self->{'fetched'}{ lc $f } = 1;
-    }
-
-    $self->{'values'}  = $hashref;
+        }
+        #$self->{'values'}  = $hashref;
     $self->{'decoded'} = {};
     return $self->id();
 }
@@ -1047,9 +1046,16 @@
 
     return ( 0, "Couldn't execute query" ) unless $sth;
 
-    $self->{'values'}  = $sth->fetchrow_hashref;
+   my $hashref  = $sth->fetchrow_hashref;
+    delete $self->{values} ;
     $self->{'fetched'} = {};
     $self->{'decoded'} = {};
+    #foreach my $f ( keys %$hashref ) { $self->{'fetched'}{  $f } = 1; }
+    foreach my $col (map {$_->name} $self->columns) {
+        next unless $hashref->{lc($col)};
+        $self->{'fetched'}{$col} = 1;
+        $self->{'values'}->{$col} = $hashref->{lc($col)};
+    }
     if ( !$self->{'values'} && $sth->err ) {
         return ( 0, "Couldn't fetch row: " . $sth->err );
     }
@@ -1066,7 +1072,7 @@
     }
 
     foreach my $f ( keys %{ $self->{'values'} } ) {
-        $self->{'fetched'}{ lc $f } = 1;
+        $self->{'fetched'}{ $f } = 1;
     }
     return ( 1, "Found object" );
 


More information about the Jifty-commit mailing list