From: Peter Rabbitson Date: Tue, 3 Nov 2015 10:47:34 +0000 (+0100) Subject: Stop requiring explicit bindtype specification for non-scalar references X-Git-Tag: v0.082840~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=e407b4ac86ccfbd6e721d459c04561899a701bac Stop requiring explicit bindtype specification for non-scalar references ( 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... ribasushi: why does DBIC think every DBD needs speical attrs to bind non-scalar values? DBD::Pg handles binding arrayrefs autmoatically ilmari: at the time this was written DBD::Pg *did not* auto-infer bindtype for arrays, that's a relatively new thing ilmari: hmmm... this does not seem to be the case, will dig deeper... --- diff --git a/Changes b/Changes index 6c9198c..5f78107 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ 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! diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index f9be97b..9600389 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1728,7 +1728,6 @@ sub _resolve_bindattrs { }; return [ map { - my $resolved = ( ref $_ ne 'ARRAY' or @$_ != 2 ) ? [ {}, $_ ] : ( ! defined $_->[0] ) ? [ {}, $_->[1] ] : (ref $_->[0] eq 'HASH') ? [( @@ -1745,31 +1744,6 @@ sub _resolve_bindattrs { : [ $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 ]; } diff --git a/t/72pg.t b/t/72pg.t index c1105fd..18f02c8 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -293,7 +293,7 @@ for my $use_insert_returning ($test_server_supports_insert_returning # 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; diff --git a/t/sqlmaker/bind_transport.t b/t/sqlmaker/bind_transport.t index 2d33352..3097191 100644 --- a/t/sqlmaker/bind_transport.t +++ b/t/sqlmaker/bind_transport.t @@ -103,45 +103,30 @@ shorthand_check( '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 {