X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=ad9eb4fe5a6c22a5c1f36db6bfab3826105d0df4;hb=64eae6a8efe2316258e78e200e50cbaff6ab10fd;hp=f4d4c0bd597eca78f869ea5b4b6ee96a0639166a;hpb=27fa2a14ad5d889570cf3edc42a031050046ffbc;p=dbsrgits%2FSQL-Abstract.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index f4d4c0b..ad9eb4f 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -27,7 +27,7 @@ BEGIN { # GLOBALS #====================================================================== -our $VERSION = '1.82'; +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, @@ -3269,4 +3296,3 @@ terms as perl itself (either the GNU General Public License or the Artistic License) =cut -