Hi,
Programming language: Delphi with pcre-compatible component
The question is: Split the SQL-statement items to:
-type (select|insert|delete|truncate table)
-distinct mode if exist (is disitinct|is not distinct)
-top if exist (top statement - rows or persent)
-join if exist (type of join, cross-table and cross-condition)
Thats what I have to this moment:
and this is the regex I made to this moment:
(?<Type>(select|insert|update|delete|truncate\s*table))\s*(?<Distinct>distinct)?\s*(Top\s*(?<Top>[\d]*))\s*.*from\s*(?<Table>[\w\d\[\]\.()'"]+)\s*((?<JoinType>|inner|outer|left|right)?\s*join\s*(?<JoinTable>[\w\d\[\]\.'"]+)\s*on\s*(?<JoinCond>[\w\d\[\]\.()'"]+\s*[=<>!]{1,2}\s*[\w\d\[\]\.'"]+))?\s*
and example SQL
select top 1000 dbo.[Database1].ForeingTable.Column1 as Alias1, 'N\A' As Alias2, 0 as Alias3, max(Column2) as Alias3, Column3 from table1 join table2 on table1.pk=table2.fk inner joint table3 on table1.pk = table2.fk order ... group ..
And the problem is what i catch only first of join conditions, not all
I know, I write sample sql statement very hardly
Thanks for all of You, Anton