From: Sebastian Riedel Date: Sun, 28 Jan 2018 11:34:40 +0000 (+0100) Subject: Add overloadable _select_fields method X-Git-Tag: v1.86~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Abstract.git;a=commitdiff_plain;h=daa4ccdd1890db8dd6b15a512a2c4f91617aa5fb Add overloadable _select_fields method Consistent with _update_set_values and _insert_values --- diff --git a/Changes b/Changes index 051d029..e2ca8f4 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for SQL::Abstract - Remove obsolete documentation about arrayrefref as the $source argument for ->select (removed in version 1.74) + - Factor out the field list part of SELECT for subclassability (GH#13) 1.85 - 2018-01-27 - Restore perl version requirement missed in the Distar port diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index d30a7e3..bd512ca 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -464,17 +464,24 @@ sub select { my $where = shift; my $order = shift; - my($where_sql, @bind) = $self->where($where, $order); + my ($fields_sql, @bind) = $self->_select_fields($fields); - my $f = (ref $fields eq 'ARRAY') ? join ', ', map { $self->_quote($_) } @$fields - : $fields; - my $sql = join(' ', $self->_sqlcase('select'), $f, + my ($where_sql, @where_bind) = $self->where($where, $order); + push @bind, @where_bind; + + my $sql = join(' ', $self->_sqlcase('select'), $fields_sql, $self->_sqlcase('from'), $table) . $where_sql; return wantarray ? ($sql, @bind) : $sql; } +sub _select_fields { + my ($self, $fields) = @_; + return ref $fields eq 'ARRAY' ? join ', ', map { $self->_quote($_) } @$fields + : $fields; +} + #====================================================================== # DELETE #======================================================================