Subject: | Cannot parse columns names with spaces |
It seems the parser cannot handle column names that contain spaces. Here are two examples that break:
~$ perl -MSQL::Statement -le 'SQL::Statement->new("SELECT `a b` FROM c",SQL::Parser->new)'
Bad table or column name: '`a b`' has chars not alphanumeric or underscore! at /usr/local/share/perl/5.20.1/SQL/Statement.pm line 88.
~$ perl -MSQL::Statement -le 'SQL::Statement->new("SELECT [a b] FROM c",SQL::Parser->new)'
Bad table or column name: '[a b]' has chars not alphanumeric or underscore! at /usr/local/share/perl/5.20.1/SQL/Statement.pm line 88.
~$
Looking at the source code it seems that a /\W/ match will trigger failure:
###################################################################
# IDENTIFIER ::= <alphabetic_char> { <alphanumeric_char> | _ }...
#
# and must not be a reserved word or over 128 chars in length
###################################################################
sub IDENTIFIER
{
my ( $self, $id ) = @_;
...
my $err = "Bad table or column name: '$id' "; # BAD CHARS
if ( $id =~ /\W/ )
{
$err .= "has chars not alphanumeric or underscore!";
return $self->do_err($err);
}
...
}
I'm not sure what better regular expression would be to allow spaces in column names. Perhaps it would be better to have an option to altogether disable constraints on characters in columns names?