From: Matt S Trout Date: Sat, 6 Apr 2019 02:55:34 +0000 (+0000) Subject: centralise field and value aqts for insert X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=438b8c7ce54e8d97baca64ec3985696403894dec;p=scpubgit%2FQ-Branch.git centralise field and value aqts for insert --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 03f9496..094c254 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -266,34 +266,35 @@ sub insert { my $fields; - my $v_aqt = do { + my ($f_aqt, $v_aqt) = do { if (is_literal_value($data)) { - $self->expand_expr($data); + (undef, $self->expand_expr($data)); } else { - ($fields, my $values) = ( + my ($fields, $values) = ( ref($data) eq 'HASH' ? ([ sort keys %$data ], [ @{$data}{sort keys %$data} ]) - : (undef, $data) + : ([], $data) ); # no names (arrayref) means can't generate bindtype !($fields) && $self->{bindtype} eq 'columns' && belch "can't do 'columns' bindtype when called with arrayref"; - +{ -row => [ - map { - local our $Cur_Col_Meta = $fields->[$_]; - $self->_expand_insert_value($values->[$_]) - } 0..$#$values - ] }; + +( + (@$fields + ? $self->expand_expr({ -row => $fields }, -ident) + : undef + ), + +{ -row => [ + map { + local our $Cur_Col_Meta = $fields->[$_]; + $self->_expand_insert_value($values->[$_]) + } 0..$#$values + ] }, + ); } }; - my $f_aqt = (@$fields - ? $self->expand_expr({ -row => $fields }, -ident) - : undef - ); - my @parts = ([ $self->_sqlcase('insert into').' '.$table ]); push @parts, [ $self->render_aqt($f_aqt) ] if $f_aqt; push @parts, [ $self->render_aqt($v_aqt) ];