Skip to content

Proposed fix for #13 that keeps scalar -columns scalar #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/SQL/Abstract/More.pm
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,22 @@ sub select {
# into a separate list @post_select, later re-injected into the SQL
my @cols = ref $args{-columns} ? @{$args{-columns}} : $args{-columns};
my @post_select;
push @post_select, shift @cols while @cols && $cols[0] =~ s/^-//;
foreach my $col (@cols) {
# extract alias, if any
if ($col =~ /^\s* # ignore insignificant leading spaces
(.*[^|\s]) # any non-empty string, not ending with ' ' or '|'
\| # followed by a literal '|'
(\w+) # followed by a word (the alias))
\s* # ignore insignificant trailing spaces
$/x) {
$aliased_columns{$2} = $1;
$col = $self->column_alias($1, $2);
if (ref $args{-columns}) {
push @post_select, shift @cols while @cols && $cols[0] =~ s/^-//;
foreach my $col (@cols) {
# extract alias, if any
if ($col =~ /^\s* # ignore insignificant leading spaces
(.*[^|\s]) # any non-empty string, not ending with ' ' or '|'
\| # followed by a literal '|'
(\w+) # followed by a word (the alias))
\s* # ignore insignificant trailing spaces
$/x) {
$aliased_columns{$2} = $1;
$col = $self->column_alias($1, $2);
}
}
$args{-columns} = \@cols;
}
$args{-columns} = \@cols;

# reorganize pagination
if ($args{-page_index} || $args{-page_size}) {
Expand Down
12 changes: 11 additions & 1 deletion t/01-sql_abstract_more.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Test::More;
use SQL::Abstract::Test import => [qw/is_same_sql_bind/];

use constant N_DBI_MOCK_TESTS => 2;
use constant N_BASIC_TESTS => 68;
use constant N_BASIC_TESTS => 69;
plan tests => (N_BASIC_TESTS + N_DBI_MOCK_TESTS);

diag( "Testing SQL::Abstract::More $SQL::Abstract::More::VERSION, Perl $], $^X" );
Expand Down Expand Up @@ -842,3 +842,13 @@ is_same_sql_bind(

[],
);

# raw columns
($sql, @bind) = $sqla->select(
-columns => 'Foo.foo, Foo.bar',
-from => 'Foo'
);
is_same_sql_bind(
$sql, \@bind,
'SELECT Foo.foo, Foo.bar FROM "Foo"', [],
);
2 changes: 1 addition & 1 deletion t/rt_099455.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ my $sqla = SQL::Abstract::More->new();

my ($sql,@bind) = $sqla->select(
-from => 'foo',
-columns => q[ concat_ws( ' ', t2.first_name,t2.last_name )|assigned_by_long ],
-columns => [ q[ concat_ws( ' ', t2.first_name,t2.last_name )|assigned_by_long ] ],
);

is_same_sql_bind (
Expand Down