From: Matt S Trout Date: Sat, 6 Apr 2019 02:55:34 +0000 (+0000) Subject: centralise field and value aqts for insert X-Git-Tag: v2.000000~3^2~278 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2ac24eedd354eb5c83b1bf99df7e6094c9f15e83;p=dbsrgits%2FSQL-Abstract.git centralise field and value aqts for insert --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 94974fd..0059707 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) ];