Bumping version to 1.83
[dbsrgits/SQL-Abstract.git] / lib / SQL / Abstract.pm
index 4017d64..ad9eb4f 100644 (file)
@@ -27,7 +27,7 @@ BEGIN {
 # GLOBALS
 #======================================================================
 
-our $VERSION  = '1.81';
+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
@@ -1419,7 +1433,7 @@ sub _quote {
 
 
 # Conversion, if applicable
-sub _convert ($) {
+sub _convert {
   #my ($self, $arg) = @_;
   if ($_[0]->{convert}) {
     return $_[0]->_sqlcase($_[0]->{convert}) .'(' . $_[1] . ')';
@@ -1428,7 +1442,7 @@ sub _convert ($) {
 }
 
 # And bindtype
-sub _bindtype (@) {
+sub _bindtype {
   #my ($self, $col, @vals) = @_;
   # called often - tighten code
   return $_[0]->{bindtype} eq 'columns'
@@ -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,
@@ -2904,32 +2931,38 @@ script.
 =head1 ORDER BY CLAUSES
 
 Some functions take an order by clause. This can either be a scalar (just a
-column name,) a hash of C<< { -desc => 'col' } >> or C<< { -asc => 'col' } >>,
-or an array of either of the two previous forms. Examples:
-
-               Given            |         Will Generate
-    ----------------------------------------------------------
-                                |
-    \'colA DESC'                | ORDER BY colA DESC
-                                |
-    'colA'                      | ORDER BY colA
-                                |
-    [qw/colA colB/]             | ORDER BY colA, colB
-                                |
-    {-asc  => 'colA'}           | ORDER BY colA ASC
-                                |
-    {-desc => 'colB'}           | ORDER BY colB DESC
-                                |
-    ['colA', {-asc => 'colB'}]  | ORDER BY colA, colB ASC
-                                |
-    { -asc => [qw/colA colB/] } | ORDER BY colA ASC, colB ASC
-                                |
-    [                           |
-      { -asc => 'colA' },       | ORDER BY colA ASC, colB DESC,
-      { -desc => [qw/colB/],    |          colC ASC, colD ASC
-      { -asc => [qw/colC colD/],|
-    ]                           |
-    ===========================================================
+column name), a hashref of C<< { -desc => 'col' } >> or C<< { -asc => 'col' }
+>>, a scalarref, an arrayref-ref, or an arrayref of any of the previous
+forms. Examples:
+
+               Given              |         Will Generate
+    ---------------------------------------------------------------
+                                  |
+    'colA'                        | ORDER BY colA
+                                  |
+    [qw/colA colB/]               | ORDER BY colA, colB
+                                  |
+    {-asc  => 'colA'}             | ORDER BY colA ASC
+                                  |
+    {-desc => 'colB'}             | ORDER BY colB DESC
+                                  |
+    ['colA', {-asc => 'colB'}]    | ORDER BY colA, colB ASC
+                                  |
+    { -asc => [qw/colA colB/] }   | ORDER BY colA ASC, colB ASC
+                                  |
+    \'colA DESC'                  | ORDER BY colA DESC
+                                  |
+    \[ 'FUNC(colA, ?)', $x ]      | ORDER BY FUNC(colA, ?)
+                                  |   /* ...with $x bound to ? */
+                                  |
+    [                             | 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 ? */
+    ===============================================================
 
 
 
@@ -3263,4 +3296,3 @@ terms as perl itself (either the GNU General Public License or
 the Artistic License)
 
 =cut
-