Subject: | Unable to process complex SQL statement with bracket before IN clause |
Date: | Thu, 13 Feb 2020 15:19:41 +0000 |
To: | "bug-SQL-Statement [at] rt.cpan.org." <"bug-SQL-Statement [at] rt.cpan.org." [...] xx1.develooper.com> |
From: | Mark R <mark_robbins1 [...] hotmail.com> |
Hello,
could you please investigate this problem.
It looks like the parser can't handle certain types of complex SQL statements.
SQL statement:
select * from docs where (sourcetable = 'AA' and recid = 11111 ) or ( sourcetable='AA' and sourceid in (select infouid from aa where aaid= '' and class= '' )) or ( sourcetable='BB' and sourceid in (select infouid from bb where bbid= '' and class= '' ))
This was adapted from an ORACLE database. the table/column names and values have been substituted for the real values.
code sample
====
#### this is an example of the full SQL but a shorter example is included below
###my $sqlStmtStr = "select * from docs where (sourcetable = 'AA' and recid = 11111 ) or ( sourcetable='AA' and sourceid in (select infouid from aa where aaid= '' and class= '' )) or ( sourcetable='BB' and sourceid in (select infouid from bb where bbid= '' and class= '' )) ";
my $sqlStmtStr = "select * from docs where ( sourceid in (select infouid from aa where aaid= '' )) ";
my $sqlParser = SQL::Parser->new();
$sqlParser->{RaiseError} = 0;
$sqlParser->{PrintError} = 1;
print STDERR "about to process: $sqlStmtStr\n";
my $sqlStmt = SQL::Statement->new($sqlStmtStr,$sqlParser);
Error messages/warnings
=====
about to process: select * from docs where ( sourceid in (select infouid from aa where aaid= '' ))
Bad table or column name: 'sourceid in select infouid from aa where aaid' has chars not alphanumeric or underscore! at /home/xxxxx/perl5/lib/site_perl/5.26.1/SQL/Statement.pm line 90.
Couldn't find predicate! at /home/xxxxx/perl5/lib/site_perl/5.26.1/SQL/Statement.pm line 90.
version info
====
Perl version:
This is perl 5, version 26, subversion 1 (v5.26.1) built for i686-linux
[xxxxx@localhost outputArchive]$ uname -a
Linux localhost.localdomain 2.6.32-358.11.1.el6.i686 #1 SMP Wed Jun 12 01:01:27 UTC 2013 i686 i686 i386 GNU/Linux
cpan[4]> i SQL::Parser
Module id = SQL::Parser
CPAN_USERID REHSACK (Jens Rehsack <rehsack@cpan.org>)
CPAN_VERSION 1.412
CPAN_FILE R/RE/REHSACK/SQL-Statement-1.412.tar.gz
UPLOAD_DATE 2017-04-06
MANPAGE SQL::Parser -- validate and parse SQL strings
INST_FILE /home/xxxxx/perl5/lib/site_perl/5.26.1/SQL/Parser.pm
INST_VERSION 1.412
cpan[5]> i SQL::Statement
Module id = SQL::Statement
CPAN_USERID REHSACK (Jens Rehsack <rehsack@cpan.org>)
CPAN_VERSION 1.412
CPAN_FILE R/RE/REHSACK/SQL-Statement-1.412.tar.gz
UPLOAD_DATE 2017-04-06
MANPAGE SQL::Statement - SQL parsing and processing engine
INST_FILE /home/xxxxx/perl5/lib/site_perl/5.26.1/SQL/Statement.pm
INST_VERSION 1.412
thanks.
mark