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

Get parameters WITH parameters in a query. #31

Closed
surister opened this issue Jun 6, 2024 · 1 comment
Closed

Get parameters WITH parameters in a query. #31

surister opened this issue Jun 6, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request javascript About the Javascript package python About the Python package

Comments

@surister
Copy link
Collaborator

surister commented Jun 6, 2024

Example:

stmt = sqlparse('CREATE TABLE test (A text) WITH ("allocation.max_retries" = $1, "myawesomepassword = $2")')[0]
stmt.with_parameters
>>> {"allocation.max_retries": '$1', "myawesomepassword": '$2'}

Todo: Identify in which parts of the SQL dialect the with params exists (maybe only implement from CREATE table for now and add more later?).
- Create

How to get the parameters from CREATE statement

    def get_text(self, node):
        if node:
            return node.getText()
        return node

    def visitCreateTable(self, ctx:SqlBaseParser.CreateTableContext):
        properties = ctx.withProperties().genericProperties().genericProperty()

        for property in properties:
            print(self.get_text(property.ident()), self.get_text(property.expr()))

Missing: Javascript target implementation

@surister surister added enhancement New feature or request python About the Python package javascript About the Javascript package labels Jun 6, 2024
@surister
Copy link
Collaborator Author

surister commented Jun 10, 2024

    def visitGenericProperties(self, ctx: SqlBaseParser.GenericPropertiesContext):
        properties = ctx.genericProperty()

        for property in properties:
            print(self.get_text(property.ident()), self.get_text(property.expr()))

Is more generic (the post factum joke is that visitGeneric is more generic, heheheh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request javascript About the Javascript package python About the Python package
Projects
None yet
Development

No branches or pull requests

1 participant