Dynamic query Parsing Issue using antlr4

138 views
Skip to first unread message

Somnath Banerjee

unread,
Jan 9, 2017, 12:17:50 AM1/9/17
to antlr-discussion

We are trying to convert Oracle pl/sql to sql server t-sql. We are using the oracle grammar file as per the below url. I have attached the grammar file as well. 


https://github.com/antlr/grammars-v4/blob/master/plsql/plsql.g4.

The pl/sql block contains/forms a query dynamically like the example below.

exec_stmt := 'UPDATE dedupjobqueue SET status = ''COMPLETED'' WHERE bank_id = ''' || v_bank_id ||''' AND orgkey ='''|| sorgkey||''' and JobID != '|| JobID || '';

The translation to t-sql construct is having some issues. The result being broken down incorrectly as mentioned below. Have a close look at the semicolon ";" in between the dynamic query.

SET @exec_stmt = 'Update CORPNEGATIVEJOBQUEUE SET status=''COMPLETED'' WHERE bank_id=''';

  • @v_bank_id + ''' AND CORP_key =''' + @sorgkey + ''' and JobID != ' + @JobID + ''

It should have done it as below.
SET @exec_stmt = 'Update CORPNEGATIVEJOBQUEUE SET status=''COMPLETED'' WHERE bank_id=''' + @v_bank_id + ''' AND CORP_key =''' + @sorgkey + ''' and JobID != ' + @JobID + '' ;


Can someone help in suggesting if the grammar needs to be changed to handle it and any other pointers ?

PLSQL.G4

Jim Idle

unread,
Jan 9, 2017, 12:24:38 AM1/9/17
to antlr-discussion
I am going to hazard a guess that this is a grammar problem, though have not looked. 

You're example of incorrect output is being formatted as a bullet list when it comes through on my email. Maybe post again in plain text?





--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Somnath Banerjee

unread,
Jan 9, 2017, 12:32:28 AM1/9/17
to antlr-discussion
..............Reposting ..............

We are trying to convert Oracle pl/sql to sql server t-sql. We are using the oracle grammar file as per the below url.

The pl/sql block contains/forms a query dynamically like the example below.

exec_stmt := 'UPDATE dedupjobqueue SET status = ''COMPLETED'' WHERE bank_id = ''' || v_bank_id ||''' AND orgkey ='''|| sorgkey||''' and JobID != '|| JobID || '';

The translation to t-sql construct is having some issues. The result being broken down incorrectly as mentioned below. Have a close look at the semicolon ";" in between the dynamic query.

SET @exec_stmt = 'Update CORPNEGATIVEJOBQUEUE SET status=''COMPLETED'' WHERE bank_id=''';
@v_bank_id + ''' AND CORP_key =''' + @sorgkey + ''' and JobID != ' + @JobID + ''

It should have done it as below.
SET @exec_stmt = 'Update CORPNEGATIVEJOBQUEUE SET status=''COMPLETED'' WHERE bank_id=''' + @v_bank_id + ''' AND CORP_key =''' + @sorgkey + ''' and JobID != ' + @JobID + '' ;

Can someone help in suggesting if the grammar needs to be changed to handle it and any other pointers ?


Somnath

Somnath Banerjee

unread,
Jan 9, 2017, 2:00:35 AM1/9/17
to antlr-discussion
Hi Jim,
    I posted again .. :) .. 


On Monday, January 9, 2017 at 10:54:38 AM UTC+5:30, Jim Idle wrote:
Reply all
Reply to author
Forward
0 new messages