Database icon indicating copy to clipboard operation
Database copied to clipboard

Include the SQL grammar

Open Hywan opened this issue 10 years ago • 7 comments

Please, see https://github.com/K-Phoen/php-sql-parser/issues/1.

Thoughts?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Hywan avatar Dec 09 '14 14:12 Hywan

It could be a really good base to build tests.

But, Do we need a full grammar ? I seen at least InsertQuery who are missing in this light grammar.

Metalaka avatar Dec 09 '14 18:12 Metalaka

DML would be great for testing, exactly. Either to validate queries build with Hoa\Database\Query or to generate queries (I don't know how it could be useful yet). Maybe the whole DML (SQL2) is not that difficult. Thoughts?

Hywan avatar Dec 09 '14 20:12 Hywan

Implementing just SQL92 parsing seems feasible: http://savage.net.au/SQL/sql-92.bnf.html

Using it... not so much. The problem is that SQL92 is not really supported cross-vendor :-\

Ocramius avatar Jan 13 '16 10:01 Ocramius

Is it possible to first normalize vendor-SQL to standard-SQL and then apply the grammar?

Hywan avatar Jan 13 '16 10:01 Hywan

@Hywan don't think so: it's not a 1:1 transformation anyway

Ocramius avatar Jan 13 '16 10:01 Ocramius

Keeping it SQL92 is feasible, then generating vendor-specific from SQL92, but generating SQL92 from vendor-specific is a huge project (basically becomes a transpiler).

Ocramius avatar Jan 13 '16 11:01 Ocramius

There are grammars for MySQL, TSQL, PL/SQL, and SQLite available for antlr. Those would be a good starting point for parsing vendor sql into a common semantic representation. It would have to be a subset, because some things, like cursors, are not going to translate. DDL can pretty well be condensed, discarding a lot of vendor fluff. Another thing to consider is in parsing vendor dialects, we can smuggle vendor features in some cases by adding extra information to the 'common' semantic nodes, and then decorating them later when we generate vendor sql. Examples would be CLUSTERED index modifier, or LIMIT.

Take a look at SqlAlchemy's dialect system.

billschaller avatar Jan 13 '16 13:01 billschaller