From: Matt S Trout Date: Sat, 6 Apr 2019 02:58:06 +0000 (+0000) Subject: clean up insert code more X-Git-Tag: v1.90_01~256 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=70b505abd90e841d6d72c3b28978e6255688d296;p=dbsrgits%2FSQL-Abstract.git clean up insert code more --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 094c254..ec3bc01 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -266,34 +266,7 @@ sub insert { my $fields; - my ($f_aqt, $v_aqt) = do { - if (is_literal_value($data)) { - (undef, $self->expand_expr($data)); - } else { - my ($fields, $values) = ( - ref($data) eq 'HASH' ? - ([ sort keys %$data ], [ @{$data}{sort keys %$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"; - - +( - (@$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, $v_aqt) = $self->_expand_insert_values($data); my @parts = ([ $self->_sqlcase('insert into').' '.$table ]); push @parts, [ $self->render_aqt($f_aqt) ] if $f_aqt; @@ -309,6 +282,36 @@ sub insert { return wantarray ? ($sql, @bind) : $sql; } +sub _expand_insert_values { + my ($self, $data) = @_; + if (is_literal_value($data)) { + (undef, $self->expand_expr($data)); + } else { + my ($fields, $values) = ( + ref($data) eq 'HASH' ? + ([ sort keys %$data ], [ @{$data}{sort keys %$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"; + + +( + (@$fields + ? $self->expand_expr({ -row => $fields }, -ident) + : undef + ), + +{ -row => [ + map { + local our $Cur_Col_Meta = $fields->[$_]; + $self->_expand_insert_value($values->[$_]) + } 0..$#$values + ] }, + ); + } +} + # So that subclasses can override INSERT ... RETURNING separately from # UPDATE and DELETE (e.g. DBIx::Class::SQLMaker::Oracle does this) sub _insert_returning { shift->_returning(@_) }