Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDL Support #6

Open
rguryanov opened this issue May 29, 2019 · 1 comment
Open

DDL Support #6

rguryanov opened this issue May 29, 2019 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@rguryanov
Copy link

Support DDL.
Currently library does not support DDL part of sql. I would like to try partially implement ddl functionality.

Grammar to implement in that issue:
// DDL
ddl_stmt
: create_stmt
| alter_stmt
| drop_stmt;

create_stmt
: create_table_stmt
| create_index_stmt
| create_sequence_stmt
| create_procedure_stmt
| create_view_stmt
| create_trigger_stmt
;

alter_stmt:
alter_table_stmt
;

drop_stmt
: drop_index_stmt
| drop_table_stmt
| drop_trigger_stmt
| drop_view_stmt
;

I think it would be great to start from that limited grammar.

@hiro80
Copy link
Owner

hiro80 commented May 30, 2019

Thank you very much for your cooperation ! Cooperation for you to implement DDL is not spare. So, please ask me anything you do not understand.

The following outlines the steps for implementing DDL.

  1. First of all, I think that the implementation starts from the point of defining the syntax of DDL. I used only DML statements as a reference from the grammar definitions published in sqlite-parser. After that, I added and changed the grammar so that I could cope with other DBMS to some extent. So the syntax of sqlite-parser may be helpful.

  2. Next, create a class that inherits from the Node class for Statements and its lower level grammar elements. This class is a class that generates each node of Syntax tree output by miniSqlParser. It is necessary to determine which grammar element to make a class.

  3. Next, use the Antlr4 to generate a parser and a lexer code from the defined grammar.

  4. Next, create a callback function called from the parser in MakeASTListener.cs (and MakeASTListener_Expr.cs, MakeASTListener_Predicate.cs). These functions correspond to individual grammar elements. When a SQL statement is parsed, if a grammar element is found, the corresponding function is called.
    The function creates an object from the class corresponding to the grammar element and puts it on the stack (MakeASTListener._stack). In the callback function of the upper grammar element, Pop out the object pushed by the callback function of the lower grammar element, store the fetched object in the object corresponding to the upper grammar element and push it.

  5. Finally, make test code.

@hiro80 hiro80 added the enhancement New feature or request label May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants