in reply to Parse complex SQL statement

perl_help26:

I've had used SQL::Parser in the past. It worked well for my needs.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: Parse complex SQL statement
by perl_help26 (Beadle) on Jun 12, 2014 at 06:08 UTC

    Actually, I tried SQL::Parser. It really gets lost and gives me undef values for all parameters ( my guess is because it has nested queries )... Any other suggestion:S?

    $VAR1 = { 'table_names' => [ 'table1' ], 'values' => [ [ { 'value' => 'SEQ_TABLE1', 'type' => 'string', 'fullorg' => 'SEQ_TABLE1' } ] ], 'column_aliases' => {}, 'org_col_names' => [ 'PARAM1', 'PARAM2', 'PARAM3', 'PARAM4', 'PARAM5', 'PARAM6', 'PARAM7' ], 'column_defs' => [ { 'fullorg' => 'PARAM1', 'type' => 'column', 'value' => 'param1' }, { 'fullorg' => 'PARAM2', 'type' => 'column', 'value' => 'param2' }, { 'fullorg' => 'PARAM3', 'type' => 'column', 'value' => 'param3' }, { 'type' => 'column', 'fullorg' => 'PARAM4', 'value' => 'param4' }, { 'value' => 'param5', 'fullorg' => 'PARAM5', 'type' => 'column' }, { 'type' => 'column', 'fullorg' => 'PARAM6', 'value' => 'param6' }, { 'value' => 'param7', 'type' => 'column', 'fullorg' => 'PARAM7' } ], 'dialect' => 'ANSI', 'org_table_names' => [ 'TABLE1' ], 'command' => 'INSERT', 'original_string' => 'INSERT INTO TABLE1 ( PARAM1, PARAM2, + PARAM3, PARAM4 , PARAM5, PARAM6 ,PARAM7)values (SELECT nextval(\'SEQ_TABLE1\') , 9613000001 , 1 , , PARAM8 , 1234 + , localtimestamp FROM TABLE2 , TABLE3 WHERE TABLE2.PARAM8= TABLE3.PARAM2 AND SETTING = 1)', 'ORG_NAME' => { 'param5' => undef, 'param3' => undef, 'param2' => undef, 'param7' => undef, 'param1' => undef, 'param6' => undef, 'param4' => undef }, 'join' => {} };