Created
February 3, 2020 18:30
-
-
Save dylanwh/57f13ace22ffdd047a57ba125c8d6919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub quote_columns { | |
my ($self, @columns) = @_; | |
my @quoted_columns = (); | |
state $sql_date_re = do { | |
my $format = quotemeta(quotemeta($self->quote('__FORMAT__'))); | |
my $sql = quotemeta($self->sql_date_format('__COLUMN__', '__FORMAT__')); | |
$sql =~ s/__COLUMN__/(.+)/; | |
$sql =~ s/$format/(.+)/; | |
$sql; | |
}; | |
warn $sql_date_re; | |
foreach (@columns) { | |
if (/^\w+$/) { | |
push @quoted_columns, $self->quote_identifier($_); | |
} | |
elsif (my ($t, $c) = /^(\w+)\.(\w+)$/) { | |
push @quoted_columns, | |
$self->quote_identifier($t) . "." . $self->quote_identifier($c); | |
} | |
elsif (my ($expr, $alias) = /^\s*(.+?)\s+AS\s+(\w+)\s*$/i) { | |
push @quoted_columns, $self->quote_columns($expr) . " AS " . $self->quote_identifier($alias); | |
} | |
elsif (my ($column, $format) = /$sql_date_re/) { | |
push @quoted_columns, $self->sql_date_format($self->quote_columns($column), $format); | |
} | |
else { | |
die "unable to quote column: $_"; | |
} | |
} | |
return join(", ", @quoted_columns); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment