Non ANSI SQL to ANSI SQL

"Andy Hallam" <ahm@exel.co.uk>
15 Aug 2001 01:39:50 -0400

          From comp.compilers

Related articles
Non ANSI SQL to ANSI SQL ahm@exel.co.uk (Andy Hallam) (2001-08-15)
| List of all articles for this month |

From: "Andy Hallam" <ahm@exel.co.uk>
Newsgroups: comp.compilers
Date: 15 Aug 2001 01:39:50 -0400
Organization: Cable & Wireless INS Customer Posting
Keywords: parse, question, comment
Posted-Date: 15 Aug 2001 01:39:50 EDT

Hi all.


Currently our applications (written using C/C++) use ODBC to connect to an
INFORMIX database using INFORMIX specific SQL SYNTAX.
i.e


SELECT a.acol, b.bcol, c.ccol
FROM a, OUTER b, c
WHERE a.acol = b.bcol
AND a.acol = c.ccol
AND a.acol2 = 'xxx'


We are now porting our applications to run against a DB2 database.
The problem I have is that DB2 does not understand INFORMIX SQL SYNTAX
(pretty obviously...) so what I need to do is convert the INFORMIX
compliant SQL into the ODBC standard that can be ran against both
databases, and so I would not have to do any branching in my source
code (apart from the initial connection that is).


For example, the above SQL in ODBC specific syntax would be thus:


SELECT a.acol, b.bcol, c.ccol
FROM {oj a LEFT OUTER JOIN b ON a.acol = b.bcol}
WHERE a.acol = c.ccol
AND a.acol2 = 'xxx';


I have 2 options:
1 - Re-write all our applications by hand with the ODBC syntax -
(250applications * average of 20 SELECT SQL statements) = 5000 SQL
statements !!!! Aahh.
2 - Write a run time parser that returns the ODBC syntax.


Option 2 is my only option.
Now I could attempt to write a parser in C++ but if I think about it for
more than a few minutes my head starts to explode!.


I know of LEX and YACC and feel that this could be an option. What I
need from you guys is some advice on this - i.e scale of difficulty
(bearing in mind the example SQL I give here is quite simple - as
those of you who have used SQL will know!).


Thanks for any advice on this.


Andy
[You're welcome to start with the SQL parser from my lex and yacc book.
-John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.