From: Matt S Trout Date: Thu, 25 Oct 2018 22:31:05 +0000 (+0000) Subject: fix undef (null) values passed to update X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c4ed66f4bd98994449fe7f34beb2820e2f8f2fcb;p=scpubgit%2FQ-Branch.git fix undef (null) values passed to update --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 6dda4ab..6b9d4a2 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -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 { diff --git a/t/01generate.t b/t/01generate.t index f328981..50e2f46 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -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` != ? )',