in reply to Re: Can I have a hard stop on a match
in thread Can I have a hard stop on a match
SQL::Parser
This was my first thought as well, to use a parser instead of a regex whenever possible. Unfortunately, it turned out that it doesn't seem to work. I checked the SQL::Statement::Syntax docs and they say that only INSERT statements of the form INSERT INTO $table [ ( $col1, ..., $colN ) ] VALUES ( $val1, ... $valN ) are supported, and "inserting from a subquery is not currently supported". Posting the code here anyway, maybe I missed something.
use warnings; use strict; use SQL::Parser; use Data::Dump; my $sql = <<'END_SQL'; INSERT INTO gl_trn ( CO_CD, GL_ACCT_CD, JRNL_CD, EMP_CD_OP, POST_DT, DES, REF, DC_CD, AMT, TRN_DT, GL_TRN_ORIGIN_CD, FINAL_DT, CO_UNIT, TRN_TIME, CMNT, BNK_ACCT_CD, BNK_TRN_TP_CD, DOC_NUM, POST_ID_NUM, BNK_CO_CD) SELECT 'XXX', GL_ACCT_CD, NULL, EMP_CD_OP, to_date('&to_post_dt', 'MMD +DRR'), 'REVERSAL'||' '||substr(des, 1, 30), 'R'||substr(REF, 1, 18), decode(dc_cd, 'C', 'D', 'D', 'C'), amt, TRUNC(SYSDATE), gl_trn_origin_cd, NULL, co_unit, floor((sysdate-trunc(sysdate))*86400), 'Auto-generated by DEV using ACREV', BNK_ACCT_CD , BNK_TRN_TP_CD, DOC_NUM, POST_ID_NUM , BNK_CO_CD FROM gl_trn WHERE post_dt = to_date('&from_post_dt', 'MMDDRR') AND jrnl_cd = 'A' AND co_cd = 'RAY' AND NOT EXISTS (SELECT 'X' FROM gl_reversed g WHERE g.GL_TRN_SEQ_NUM = gl_trn.gl_trn_seq_num); END_SQL #$sql = q{INSERT INTO foo VALUES (1, 2, 'bar');}; # simple test my $parser = SQL::Parser->new(); $parser->parse($sql) or die; dd $parser->structure; __END__ No table name specified! at sql.pl line 31. No command found! at sql.pl line 31. Died at sql.pl line 31.
|
|---|