From: Matt S Trout Date: Tue, 9 Apr 2019 17:14:53 +0000 (+0000) Subject: clean up fields/values expansion for insert X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f33d93b5ddf28a34e493913d72555b074a10a7a0;p=scpubgit%2FQ-Branch.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;