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

Handle binary char set introducer #544

Merged
merged 6 commits into from
May 23, 2022

Conversation

G1gg1L3s
Copy link
Contributor

@G1gg1L3s G1gg1L3s commented May 23, 2022

This small PR adds support of mysql _binary charset introducer, which is used at least by java frontend. I would like to add other charsets, but they are not supported by the parser yet. So, if there is no need, I wouldn't do that.

Checklist

Others are not supported yet :c
By now, it's the only one parsed charset.
[skip ci]
tests/test.py Outdated
id = get_random_id()
# DON'T EVER, EVER DO THIS
# Do not use direct string interpolation for sql values
# This is just a test example
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can avoid using raw sql and build query with sqlalchemy:

>>> from sqlalchemy.sql import expression
>>> from sqlalchemy.sql import operators
>>> unary = expression.UnaryExpression(
      sa.Column("column"), 
      operator=operators.custom_op("_binary"), 
      type_=sa.Numeric)
>>> str(unary)
'_binary "column"'

Use unary instead of self.test_table.c.value_bytes

Sqlalchemy serializes the test as:
```
INSERT ... VALUES (..., (_binary 'string')...)
```
So it's easier to add support also for parenthese expressions,
than fight with sqlalchemy.

The syntax in general [1] is defined as:
```
simple_expr:
  | (expr [, expr] ...)
  ...
```

But our parser supports only:
```
simple_expr:
  | (expr)
  ...
```

Which is enough for most real word cases.
Therefore, it's easy to add support for these expressions.

[1]: https://dev.mysql.com/doc/refman/8.0/en/expressions.html

self.schema_table.create(bind=self.engine_raw, checkfirst=True)
id = get_random_id()
insert = self.test_table.insert().values(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, if sqlalchemy compile query with parentheses, then lets test them both? and use raw sql query to use without parentheses if sqlalchemy doesn't allow compile without them

To use both: with and without parentheses around literal.
@G1gg1L3s G1gg1L3s merged commit d8c0ae9 into master May 23, 2022
@G1gg1L3s G1gg1L3s deleted the G1gg1L3s/T2579-char-set-introducer branch May 23, 2022 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants