( cherry-pick of
0e3647497e )
As ilmari correctly pointed out this is not necessary, I am not sure why I
didn't catch this on review...
<ilmari> ribasushi: why does DBIC think every DBD needs speical attrs to bind non-scalar values?
<ilmari> DBD::Pg handles binding arrayrefs autmoatically
<ribasushi> ilmari: at the time this was written DBD::Pg *did not* auto-infer bindtype for arrays, that's a relatively new thing
<ribasushi> ilmari: hmmm... this does not seem to be the case, will dig deeper...
Revision history for DBIx::Class
+ * New Features
+ - When using non-scalars (e.g. arrays) as literal bind values it is no
+ longer necessary to explicitly specify a bindtype (this turned out
+ to be a mostly useless overprotection)
+
* Fixes
- Another relatively invasive set of ::FilterColumn changes, covering
potential data loss (RT#111567). Please run your regression tests!
};
return [ map {
- my $resolved =
( ref $_ ne 'ARRAY' or @$_ != 2 ) ? [ {}, $_ ]
: ( ! defined $_->[0] ) ? [ {}, $_->[1] ]
: (ref $_->[0] eq 'HASH') ? [(
: [ $resolve_bindinfo->(
{ dbic_colname => $_->[0] }
), $_->[1] ]
- ;
-
- if (
- ! exists $resolved->[0]{dbd_attrs}
- and
- ! $resolved->[0]{sqlt_datatype}
- and
- length ref $resolved->[1]
- and
- ! is_plain_value $resolved->[1]
- ) {
- require Data::Dumper;
- local $Data::Dumper::Maxdepth = 1;
- local $Data::Dumper::Terse = 1;
- local $Data::Dumper::Useqq = 1;
- local $Data::Dumper::Indent = 0;
- local $Data::Dumper::Pad = ' ';
- $self->throw_exception(
- 'You must supply a datatype/bindtype (see DBIx::Class::ResultSet/DBIC BIND VALUES) '
- . 'for non-scalar value '. Data::Dumper::Dumper ($resolved->[1])
- );
- }
-
- $resolved;
-
} @$bind ];
}
# test inferred condition for creation
for my $cond (
{ -value => [3,4] },
- \[ '= ?' => [arrayfield => [3, 4]] ],
+ \[ '= ?' => [3, 4] ],
) {
local $TODO = 'No introspection of complex literal conditions :('
if is_literal_value $cond;
'stringifyable $object === [ {}, $object ]',
);
-throws_ok {
- shorthand_check(
+shorthand_check(
[ 2 ],
- [],
- )
-} qr !You must supply a datatype/bindtype .+ for non-scalar value \Q[ 2 ]!,
- 'exception on bare array bindvalue';
+ [ {} => [ 2 ] ],
+);
-throws_ok {
- shorthand_check(
+shorthand_check(
[ {} => [ 2 ] ],
- [],
- )
-} qr !You must supply a datatype/bindtype .+ for non-scalar value \Q[ 2 ]!,
- 'exception on untyped array bindvalue';
+ [ {} => [ 2 ] ],
+);
-throws_ok {
- shorthand_check(
+shorthand_check(
[ {}, 2, 3 ],
- [],
- )
-} qr !You must supply a datatype/bindtype .+ for non-scalar value \[ 'HASH\(\w+\)', 2, 3 \]!,
- 'exception on bare multielement array bindvalue';
+ [ {} => [ {}, 2, 3 ] ],
+);
-throws_ok {
- shorthand_check(
+shorthand_check(
bless( {}, 'Foo'),
- [],
- )
-} qr !You must supply a datatype/bindtype .+ for non-scalar value \Qbless( {}, 'Foo' )!,
- 'exception on bare object';
+ [ {} => bless( {}, 'Foo') ],
+);
-throws_ok {
- shorthand_check(
+shorthand_check(
+ [ {}, bless( {}, 'Foo') ],
[ {}, bless( {}, 'Foo') ],
- [],
- )
-} qr !You must supply a datatype/bindtype .+ for non-scalar value \Qbless( {}, 'Foo' )!,
- 'exception on untyped object';
+);
sub shorthand_check {