Author: spadkins
Date: Tue Jan 13 10:11:48 2009
New Revision: 12427

Modified:
   p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm

Log:
fix a bug with {by_expression=>1} on update

Modified: p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm Tue Jan 13 10:11:48 2009
@@ -2307,9 +2307,15 @@
     my ($self, $table, $params, $cols, $row, $options) = @_;
     $self->{error} = "";
     $options = $options ? { %$options } : {};
-    my (@bind_var_idx);
+    my $by_expression = $options->{by_expression};
+    my (@bind_var_idx, $sql);
     $options->{bind_var_idx} = \...@bind_var_idx;
-    my $sql = $self->_mk_update_sql($table, $params, $cols, undef, $options); 
# SEB removed $row, added undef
+    if ($by_expression) {
+        $sql = $self->_mk_update_sql($table, $params, $cols, $row, $options);
+    }
+    else {
+        $sql = $self->_mk_update_sql($table, $params, $cols, undef, $options);
+    }
     $self->{sql} = $sql;
 
     my $context = $self->{context};
@@ -2325,37 +2331,47 @@
         my ($column, %serializer, $serializer_name, $serializer, $sqltype, 
$colidx);
         my $column_defs = $self->{table}{$table}{column};
         eval {
-            if ($#bind_var_idx == -1) {
-                @bind_var_idx = (0 .. $#$row);
+            if ($by_expression) {
+                if ($debug_sql) {
+                    $timer = $self->_get_timer();
+                    print $App::DEBUG_FILE "DEBUG_SQL: _update() : 
by_expression\n";
+                    print $App::DEBUG_FILE $sql;
+                }
+                $retval = $dbh->do($sql);
             }
-            ### TODO: make this work with regex for retry
-            my $update_sth = $dbh->prepare($sql);
-            for (my $i = 0; $i <= $#bind_var_idx; $i++) {
-                $colidx = $bind_var_idx[$i];
-                $column = $cols->[$colidx];
-                $sqltype  = $column_defs->{$column}{sqltype};
-                $serializer_name = $column_defs->{$column}{serializer};
-                if ($serializer_name) {
-                    $serializer = $serializer{$serializer_name};
-                    if (!$serializer) {
-                        $serializer = $context->serializer($serializer_name);
-                        $serializer{$serializer_name} = $serializer;
+            else {
+                if ($#bind_var_idx == -1) {
+                    @bind_var_idx = (0 .. $#$row);
+                }
+                ### TODO: make this work with regex for retry
+                my $update_sth = $dbh->prepare($sql);
+                for (my $i = 0; $i <= $#bind_var_idx; $i++) {
+                    $colidx = $bind_var_idx[$i];
+                    $column = $cols->[$colidx];
+                    $sqltype  = $column_defs->{$column}{sqltype};
+                    $serializer_name = $column_defs->{$column}{serializer};
+                    if ($serializer_name) {
+                        $serializer = $serializer{$serializer_name};
+                        if (!$serializer) {
+                            $serializer = 
$context->serializer($serializer_name);
+                            $serializer{$serializer_name} = $serializer;
+                        }
+                        $row->[$colidx] = 
$serializer->serialize($row->[$colidx]);
                     }
-                    $row->[$colidx] = $serializer->serialize($row->[$colidx]);
+                    $update_sth->bind_param($i+1, undef, $sqltype ? {TYPE => 
$sqltype} : () );
                 }
-                $update_sth->bind_param($i+1, undef, $sqltype ? {TYPE => 
$sqltype} : () );
-            }
 
-            if ($#bind_var_idx > -1) {
-                $row = [ @{$ro...@bind_var_idx] ];
-            }
-            if ($debug_sql) {
-                $timer = $self->_get_timer();
-                print $App::DEBUG_FILE "DEBUG_SQL: _update()\n";
-                print $App::DEBUG_FILE "DEBUG_SQL: bind vars [", join("|",map 
{ defined $_ ? $_ : "undef" } @$row), "]\n";
-                print $App::DEBUG_FILE $sql;
+                if ($#bind_var_idx > -1) {
+                    $row = [ @{$ro...@bind_var_idx] ];
+                }
+                if ($debug_sql) {
+                    $timer = $self->_get_timer();
+                    print $App::DEBUG_FILE "DEBUG_SQL: _update()\n";
+                    print $App::DEBUG_FILE "DEBUG_SQL: bind vars [", 
join("|",map { defined $_ ? $_ : "undef" } @$row), "]\n";
+                    print $App::DEBUG_FILE $sql;
+                }
+                $retval = $update_sth->execute(@$row);
             }
-            $retval = $update_sth->execute(@$row);
 
             #$retval = $update_sth->execute();
             #$retval = $dbh->do($sql); 

Reply via email to