From c93f74ada2dfa2273ef187ebc4e781232efce28f Mon Sep 17 00:00:00 2001 From: Dmitry Latin Date: Wed, 9 Apr 2014 20:52:55 +0400 Subject: [PATCH 1/2] Add test for update with literal bind for inflating column --- t/update/inflate_literal_bind.t | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 t/update/inflate_literal_bind.t diff --git a/t/update/inflate_literal_bind.t b/t/update/inflate_literal_bind.t new file mode 100644 index 000000000..38527e347 --- /dev/null +++ b/t/update/inflate_literal_bind.t @@ -0,0 +1,34 @@ +use strict; +use warnings; + +use Test::More; +use Test::Warn; +use Try::Tiny; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $event = $schema->resultset("Event")->find(1); + +ok( + $event->update( + { + starts_at => \[ + 'MAX(datetime(?), datetime(?))', '2006-04-25T22:24:33', + '2007-04-25T22:24:33', + ] + } + ), + 'update without error' +); + +$event = $event->get_from_storage(); + +is( + $event->starts_at . '', + '2007-04-25T22:24:33', + 'starts_at updated properly' +); + +done_testing; From 0a242eea697bc23e5085448e00d31818f93fc102 Mon Sep 17 00:00:00 2001 From: Dmitry Latin Date: Wed, 9 Apr 2014 21:32:46 +0400 Subject: [PATCH 2/2] Fix bug for literal bind for ARRAY --- lib/DBIx/Class/InflateColumn.pm | 10 +++++++++- .../{inflate_literal_bind.t => array_literal_bind.t} | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) rename t/update/{inflate_literal_bind.t => array_literal_bind.t} (83%) diff --git a/lib/DBIx/Class/InflateColumn.pm b/lib/DBIx/Class/InflateColumn.pm index 9214582a4..ae98d75e2 100644 --- a/lib/DBIx/Class/InflateColumn.pm +++ b/lib/DBIx/Class/InflateColumn.pm @@ -116,7 +116,15 @@ sub _deflated_column { my ($self, $col, $value) = @_; # return $value unless ref $value && blessed($value); # If it's not an object, don't touch it ## Leave scalar refs (ala SQL::Abstract literal SQL), untouched, deflate all other refs - return $value unless (ref $value && ref($value) ne 'SCALAR'); + ## Also leave ref refs if it is ARRAY + return $value + unless ( + ref $value + && !( ref($value) eq 'SCALAR' + || ( ref($value) eq 'REF' && ref($$value) eq 'ARRAY' ) + ) + ); + my $info = $self->column_info($col) or $self->throw_exception("No column info for $col"); return $value unless exists $info->{_inflate_info}; diff --git a/t/update/inflate_literal_bind.t b/t/update/array_literal_bind.t similarity index 83% rename from t/update/inflate_literal_bind.t rename to t/update/array_literal_bind.t index 38527e347..19c7e9702 100644 --- a/t/update/inflate_literal_bind.t +++ b/t/update/array_literal_bind.t @@ -15,7 +15,8 @@ ok( $event->update( { starts_at => \[ - 'MAX(datetime(?), datetime(?))', '2006-04-25T22:24:33', + 'MAX(starts_at, datetime(?), datetime(?))', + '2006-04-25T22:24:33', '2007-04-25T22:24:33', ] }