From: Matt S Trout Date: Sun, 31 Jul 2011 10:01:58 +0000 (+0000) Subject: factor out from+where handling and port DELETE X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7dc2102a3c3fa1abb5313fa92006566a7c35f54b;p=dbsrgits%2FSQL-Abstract.git factor out from+where handling and port DELETE --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index e817a8d..4f8bb18 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -12,7 +12,7 @@ use List::Util (); use Scalar::Util (); use Data::Query::Constants qw( DQ_IDENTIFIER DQ_OPERATOR DQ_VALUE DQ_LITERAL DQ_JOIN DQ_SELECT DQ_ORDER - DQ_WHERE + DQ_WHERE DQ_DELETE ); use Data::Query::ExprHelpers qw(perl_scalar_value); @@ -442,13 +442,8 @@ sub update { # SELECT #====================================================================== - -sub select { - my $self = shift; - my $table = shift; - my $fields = shift || '*'; - my $where = shift; - my $order = shift; +sub _source_to_dq { + my ($self, $table, $where) = @_; my $source_dq = $self->_table_to_dq($table); @@ -460,6 +455,18 @@ sub select { }; } + $source_dq; +} + +sub select { + my $self = shift; + my $table = shift; + my $fields = shift || '*'; + my $where = shift; + my $order = shift; + + my $source_dq = $self->_source_to_dq($table, $where); + my $final_dq = { type => DQ_SELECT, select => [ @@ -483,14 +490,15 @@ sub select { sub delete { my $self = shift; - my $table = $self->_table(shift); - my $where = shift; - - - my($where_sql, @bind) = $self->where($where); - my $sql = $self->_sqlcase('delete from') . " $table" . $where_sql; + $self->_render_dq($self->_delete_to_dq(@_)); +} - return wantarray ? ($sql, @bind) : $sql; +sub _delete_to_dq { + my $self = shift; + +{ + type => DQ_DELETE, + from => $self->_source_to_dq(@_) + } }