X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=ad9eb4fe5a6c22a5c1f36db6bfab3826105d0df4;hb=64eae6a8efe2316258e78e200e50cbaff6ab10fd;hp=5dc55c7648321b886cd2c65dd4bf857ed1458520;hpb=f0724630077f85e0127fc4cb51e108c484feac61;p=dbsrgits%2FSQL-Abstract.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 5dc55c7..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, @@ -2908,33 +2935,33 @@ 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 + 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 ? */ - | - [ | - { -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 ], | - ] | + | + '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 ? */ =============================================================== @@ -3269,4 +3296,3 @@ terms as perl itself (either the GNU General Public License or the Artistic License) =cut -