fix undef (null) values passed to update
Matt S Trout [Thu, 25 Oct 2018 22:31:05 +0000 (22:31 +0000)]
lib/SQL/Abstract.pm
t/01generate.t

index 6dda4ab..6b9d4a2 100644 (file)
@@ -382,6 +382,7 @@ sub _expand_update_set_values {
   $self->_expand_maybe_list_expr( [
     map {
       my ($k, $set) = @$_;
+      $set = { -bind => $_ } unless defined $set;
       +{ -op => [ '=', { -ident => $k }, $set ] };
     }
     map {
index f328981..50e2f46 100644 (file)
@@ -83,6 +83,13 @@ my @tests = (
       },
       {
               func   => 'update',
+              args   => ['test', {a => undef }, {a => 'boom'}],
+              stmt   => 'UPDATE test SET a = ? WHERE ( a = ? )',
+              stmt_q => 'UPDATE `test` SET `a` = ? WHERE ( `a` = ? )',
+              bind   => [undef,'boom']
+      },
+      {
+              func   => 'update',
               args   => ['test', {a => 'boom'}, { a => {'!=', "bang" }} ],
               stmt   => 'UPDATE test SET a = ? WHERE ( a != ? )',
               stmt_q => 'UPDATE `test` SET `a` = ? WHERE ( `a` != ? )',