Author: spadkins
Date: Fri Feb 27 20:44:38 2009
New Revision: 12554

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

Log:
fixed a bug when updating a row with keycolidx

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 Fri Feb 27 20:44:38 2009
@@ -1636,12 +1636,18 @@
                 $col = $cols->[$colidx];
                 if (!defined $row || $#$row == -1) {
                     $value = "?";
+                    if ($column_defs->{$col}{dbexpr_update}) {
+                        $value = sprintf($column_defs->{$col}{dbexpr_update}, 
$value, $value, $value, $value, $value);
+                    }
                 }
                 else {
                     $value = $row->[$colidx];
                     if (!defined $value) {
                         $value = "NULL";
                     }
+                    elsif ($column_defs->{$col}{dbexpr_update}) {
+                        $value = sprintf($column_defs->{$col}{dbexpr_update}, 
$value, $value, $value, $value, $value);
+                    }
                     else {
                         $quoted = (defined 
$column_defs->{$col}{quoted})?($column_defs->{$col}{quoted}):($value !~ 
/^-?[0-9.]+$/);
                         if ($quoted) {
@@ -1650,7 +1656,7 @@
                     }
                 }
                 push(@where, "$col = $value");
-                push(@where_bind_var_idx, $i);
+                push(@where_bind_var_idx, $colidx);
                 $noupdate[$colidx] = 1;
             }
         }

Modified: p5ee/trunk/App-Repository/t/DBI-update.t
==============================================================================
--- p5ee/trunk/App-Repository/t/DBI-update.t    (original)
+++ p5ee/trunk/App-Repository/t/DBI-update.t    Fri Feb 27 20:44:38 2009
@@ -165,7 +165,7 @@
 # True updates
 
######################################################################################3
 
-my ($nrows);
+my ($nrows, $row);
 
 $expect_sql = <<EOF;
 update test_person set
@@ -191,8 +191,8 @@
                       [ "birth_dt", "change_dttm", "modify_dttm", "age", 
"chess_rating", "last_name" ],
                       [ "1960-01-01", "2009-02-26 13:14:22", "2009-02-26 
13:14:23", 99, 200.1, "the great" ]);
 is($nrows, 1, "update(table, [DATE,DATETIME,TIMESTAMP,INT,FLOAT,STRING])");
-my $row = $rep->get_row("test_person", 1,
-                      [ "birth_dt", "change_dttm", "modify_dttm", "age", 
"chess_rating", "last_name" ]);
+$row = $rep->get_row("test_person", 1,
+                      [ "birth_dt", "change_dttm", "modify_dttm", "age", 
"chess_rating", "last_name", "first_name" ]);
 is($row->[0], "1960-01-01",          "update() of DATE validated");
 is($row->[1], "2009-02-26 13:14:22", "update() of DATETIME validated");
 is($row->[2], "2009-02-26 13:14:23", "update() of TIMESTAMP validated");
@@ -200,5 +200,22 @@
 is($row->[4], 200.1,                 "update() of FLOAT validated");
 is($row->[5], "the great",           "update() of STRING validated");
 
+$row->[1] = "2009-02-26 13:18:01";
+$row->[2] = "2009-02-26 13:19:22";
+$row->[3] = 105;
+$row->[4] = 213.7;
+
+$nrows = $rep->update("test_person", [0, 5, 6],
+                      [ "birth_dt", "change_dttm", "modify_dttm", "age", 
"chess_rating", "last_name", "first_name" ], $row);
+is($nrows, 1, "update(table, ARRAY, COLARRAY, VALARRAY) updated one row");
+
+$row = $rep->get_row("test_person", 1,
+                      [ "birth_dt", "change_dttm", "modify_dttm", "age", 
"chess_rating", "last_name", "first_name" ]);
+
+is($row->[1], "2009-02-26 13:18:01", "update() of DATETIME validated");
+is($row->[2], "2009-02-26 13:19:22", "update() of TIMESTAMP validated");
+is($row->[3], 105,                   "update() of INT validated");
+is($row->[4], 213.7,                 "update() of FLOAT validated");
+
 exit 0;
 

Reply via email to