Bumping version to 1.83
[dbsrgits/SQL-Abstract.git] / lib / SQL / Abstract.pm
index e03d341..ad9eb4f 100644 (file)
@@ -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<WHERE clause|/WHERE CLAUSES>.
 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<returning> option to
+L<insert|/insert($table, \@values || \%fieldvals, \%options)>.
+
+=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
-