From: Peter Rabbitson Date: Sun, 7 Mar 2010 21:51:20 +0000 (+0000) Subject: Factor out insert returning generator X-Git-Tag: v1.70~129 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b1fe79d4bffb56c2aecba7812feb5790daedd9e;p=dbsrgits%2FSQL-Abstract.git Factor out insert returning generator --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 58f99cc..722743a 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -118,18 +118,24 @@ sub insert { my ($sql, @bind) = $self->$method($data); $sql = join " ", $self->_sqlcase('insert into'), $table, $sql; - if (my $fields = $options->{returning}) { - my $f = $self->_SWITCH_refkind($fields, { - ARRAYREF => sub {join ', ', map { $self->_quote($_) } @$fields;}, - SCALAR => sub {$self->_quote($fields)}, - SCALARREF => sub {$$fields}, - }); - $sql .= join " ", $self->_sqlcase(' returning'), $f; + if (my $ret = $options->{returning}) { + $sql .= $self->_insert_returning ($ret); } return wantarray ? ($sql, @bind) : $sql; } +sub _insert_returning { + my ($self, $fields) = @_; + + my $f = $self->_SWITCH_refkind($fields, { + ARRAYREF => sub {join ', ', map { $self->_quote($_) } @$fields;}, + SCALAR => sub {$self->_quote($fields)}, + SCALARREF => sub {$$fields}, + }); + return join (' ', $self->_sqlcase(' returning'), $f); +} + sub _insert_HASHREF { # explicit list of fields and then values my ($self, $data) = @_;