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-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=0e3647497ee2cbaa511b05262c902ee50d813c32 Stop requiring explicit bindtype specification for non-scalar references 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 9bb59ff..c9d9966 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,9 @@ Revision history for DBIx::Class arrayref) now emits a deprecation warning * 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) - DBIx::Class::Optional::Dependencies now properly understands combinations of requirements and does the right thing with e.g. ->req_list_for([qw( rdbms_oracle ic_dt )]) bringing in the Oracle diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index eb9bd88..3e746ad 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1722,7 +1722,6 @@ sub _resolve_bindattrs { }; return [ map { - my $resolved = ( ref $_ ne 'ARRAY' or @$_ != 2 ) ? [ {}, $_ ] : ( ! defined $_->[0] ) ? [ {}, $_->[1] ] : (ref $_->[0] eq 'HASH') ? [( @@ -1739,31 +1738,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 ec1cab0..e1e8e0e 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -274,7 +274,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 {