From: Matt S Trout Date: Tue, 9 Apr 2019 17:14:53 +0000 (+0000) Subject: clean up fields/values expansion for insert X-Git-Tag: v2.000000~3^2~261 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=89bbac1d7e31c0af9ca408369cdcc3746445d3bb;p=dbsrgits%2FSQL-Abstract.git clean up fields/values expansion for insert --- diff --git a/lib/SQL/Abstract/Clauses.pm b/lib/SQL/Abstract/Clauses.pm index 0ae82ac..bbe1eda 100644 --- a/lib/SQL/Abstract/Clauses.pm +++ b/lib/SQL/Abstract/Clauses.pm @@ -36,6 +36,7 @@ sub register_defaults { $self->{expand_clause}{'insert.insert_into'} = sub { shift->expand_expr(@_, -ident); }; + $self->{expand_clause}{'insert.values'} = '_expand_insert_clause_values'; $self->{expand_clause}{'insert.returning'} = sub { shift->_expand_maybe_list_expr(@_, -ident); }; @@ -169,12 +170,15 @@ sub delete { sub insert { my ($self, $table, $data, $options) = @_; - my %clauses = (insert_into => $table, %{$options||{}}); - my ($f_aqt, $v_aqt) = $self->_expand_insert_values($data); - $clauses{fields} = $f_aqt if $f_aqt; - $clauses{values} = $v_aqt; + my %clauses = (insert_into => $table, values => $data, %{$options||{}}); my ($sql, @bind) = $self->render_expr({ -insert => \%clauses }); return wantarray ? ($sql, @bind) : $sql; } +sub _expand_insert_clause_values { + my ($self, $data) = @_; + my ($f_aqt, $v_aqt) = $self->_expand_insert_values($data); + return (values => $v_aqt, ($f_aqt ? (fields => $f_aqt) : ())); +} + 1;