X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=ad9eb4fe5a6c22a5c1f36db6bfab3826105d0df4;hb=64eae6a8efe2316258e78e200e50cbaff6ab10fd;hp=596c589fb0bfa624754c93322dfa74d7e39bce19;hpb=8c15b4213396b4ae2b73d44adaaaea5be2915db1;p=dbsrgits%2FSQL-Abstract.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 596c589..ad9eb4f 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -27,7 +27,7 @@ BEGIN { # GLOBALS #====================================================================== -our $VERSION = '1.81_01'; +our $VERSION = '1.83'; # This would confuse some packagers $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases @@ -227,7 +227,8 @@ sub insert { return wantarray ? ($sql, @bind) : $sql; } -# Used by DBIx::Class::SQLMaker->insert +# 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(@_) } sub _returning { @@ -436,6 +437,8 @@ sub update { return wantarray ? ($sql, @all_bind) : $sql; } +# So that subclasses can override UPDATE ... RETURNING separately from +# INSERT and DELETE sub _update_returning { shift->_returning(@_) } @@ -469,17 +472,28 @@ sub select { sub delete { - my $self = shift; - my $table = $self->_table(shift); - my $where = shift; - + my $self = shift; + my $table = $self->_table(shift); + my $where = shift; + my $options = shift; my($where_sql, @bind) = $self->where($where); my $sql = $self->_sqlcase('delete from') . " $table" . $where_sql; + if ($options->{returning}) { + my ($returning_sql, @returning_bind) = $self->_delete_returning ($options); + $sql .= $returning_sql; + push @bind, @returning_bind; + } + return wantarray ? ($sql, @bind) : $sql; } +# So that subclasses can override DELETE ... RETURNING separately from +# INSERT and UPDATE +sub _delete_returning { shift->_returning(@_) } + + #====================================================================== # WHERE: entry point @@ -2150,11 +2164,24 @@ for details. =back -=head2 delete($table, \%where) +=head2 delete($table, \%where, \%options) This takes a table name and optional hashref L. It returns an SQL DELETE statement and list of bind values. +The optional C<\%options> hash reference may contain additional +options to generate the delete SQL. Currently supported options +are: + +=over 4 + +=item returning + +See the C option to +L. + +=back + =head2 where(\%where, $order) This is used to generate just the WHERE clause. For example, @@ -2928,13 +2955,13 @@ forms. Examples: \[ 'FUNC(colA, ?)', $x ] | ORDER BY FUNC(colA, ?) | /* ...with $x bound to ? */ | - [ | - { -asc => 'colA' }, | ORDER BY colA ASC, colB DESC, - { -desc => [qw/colB/] }, | colC ASC, colD ASC, - { -asc => [qw/colC colD/] },| colE DESC, FUNC(colF, ?) - \'colE DESC', | /* ...with $x bound to ? */ - \[ 'FUNC(colF, ?)', $x ], | - ] | + [ | ORDER BY + { -asc => 'colA' }, | colA ASC, + { -desc => [qw/colB/] }, | colB DESC, + { -asc => [qw/colC colD/] },| colC ASC, colD ASC, + \'colE DESC', | colE DESC, + \[ 'FUNC(colF, ?)', $x ], | FUNC(colF, ?) + ] | /* ...with $x bound to ? */ =============================================================== @@ -3269,4 +3296,3 @@ terms as perl itself (either the GNU General Public License or the Artistic License) =cut -