Comments (3)
This should be fixed with #13
from sql-statement.
solution for this
use Modern::Perl;
my $sql1 = " SELECT CL.SHRT_NM, RT.EFF_DT, RT.EXG_RATE_VAL
FROM HTF13.CL CL, HTF13.EXG_RATE_HIST RT
WHERE RT.FRST_CCY_ID = 751 and RT.CCY_ID = CL.GRP_CL_ID and CL.CL_SCM_ID = 61 and RT.EFF_DT >= '01.08.2005' and (CL.END_DT = '31.12.9999' or CL.CL_ID =1004)";
my $sql2 = " SELECT AR.*
FROM
HTF13.AR AR LEFT OUTER JOIN HTF13.AR_X_AGN_REESTR_1
ON
HTF13.AR_X_AGN_REESTR_1.CST_AR_ID = AR.AR_ID OR
HTF13.AR_X_AGN_REESTR_1.CST_SUB_AR_ID = AR.AR_ID
WHERE
AR.AR_PPS_TP_ID = 1527 AND
AR.AR_TP_ID <> 1467 AND
HTF13.AR_X_AGN_REESTR_1.CST_AR_ID IS NULL
"
;
use SQL::Statement;
use Test::Warn;
use Test::More;
sub get_tables {
my ($sql, $parser) = @_;
my $stmt = SQL::Statement->new($sql, $parser);
return map { uc $_->name } $stmt->tables();
}
for my $sql ($sql1, $sql2) {
&process_sql($sql);
}
sub process_sql {
my ($sql) = @_;
my $parser = SQL::Parser->new();
$parser->{RaiseError} = 1;
$parser->{PrintError} = 1;
my $msg_err_or = q{Can't use OR in an ON clause!};
my $msg_err_ref = q{referenced but not found in FROM list};
my @tables = ();
my $ret = warnings_like {
eval { @tables = get_tables($sql, $parser); };
}
[qr/$msg_err_or/i], "warnings: $msg_err_or";
if ($ret) { #change OR на END
$sql =~ s/OR/AND/xmg;
my $ret2 = warnings_like {
eval { @tables = get_tables($sql, $parser); };
}
[qr/$msg_err_ref/i], "warnings: $msg_err_ref";
if ($ret2) {
use SQL::Tokenizer qw(tokenize_sql);
my $remove_white_tokens = 1;
my @tokens = SQL::Tokenizer->tokenize($sql, $remove_white_tokens);
for my $i (0 .. $#tokens) {
if (($tokens[$i] eq 'FROM') or ($tokens[$i] eq 'JOIN')) {
push @tables, $tokens[$i + 1];
}
}
}
}
say join ',', @tables;
}
done_testing();
from sql-statement.
can you add this solution to a module?
it's very tricky for me
from sql-statement.
Related Issues (6)
- having cannot have > or < HOT 2
- [BUG] join keyword NATURAL has to be matched case-insensitive
- Deep recursion on subroutine "SQL::Parser::non_parens_search"
- [BUG] SQL parser should return false if applied to "SELECT * FRoOM foo "
- Table 'AR_X_AGN_REESTR_1' referenced but not found in FROM list (HTF13.AR_X_AGN_REESTR_1,HTF13.AR,ar)! at C:/Dwimperl/perl/site/lib/SQL/Statement.pm line 88 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sql-statement.