I would like to be able to parse an arbitrary SQL SELECT statement and retrieve the various component parts (columns, relations, JOIN conditions, WHERE conditions, ORDER BY columns), ideally using Delphi. A quick google search shows several different freeware products, but it's not clear if they are complete and/or under active development.
My immediate need to just to extract the list of relations used in a series of VIEW definitions in order ensure that required views or tables exist before I try to CREATE the view. So, for instance, for the statement:
SELECT PersonID, LastName, OrderID
FROM People P INNER JOIN Orders O ON P.PersonID = O.PersonID
I need to get back the values "People" and "Orders". (Obviously, this is a simple example. I want to be able to handle more complex cases where, for instance, the word "FROM" might appear in the column list as part of an expression).
I'm trying to provide this service in a database that allows use of STDCALL functions exported from DLLs, so ideally any candidate library would be callable from Delphi or C.