Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for update with literal bind for ARRAY #44

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/DBIx/Class/InflateColumn.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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};
Expand Down
35 changes: 35 additions & 0 deletions t/update/array_literal_bind.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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(starts_at, 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;