Skip to content

Commit

Permalink
Raise exception by default in expression_to_value (#60)
Browse files Browse the repository at this point in the history
* Raise exception by default in expression_to_value

* add a comment

* fix

* comments

* fix format

* limit mysql-connector-python<9.0.0

* fix mysql-connector

* add a comment
  • Loading branch information
xiaoyu-meng-mxy authored Aug 28, 2024
1 parent 08f7c09 commit 18e6587
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion mysql_mimic/intercept.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Any

from sqlglot import expressions as exp

from mysql_mimic.errors import MysqlError, ErrorCode
from mysql_mimic.variables import DEFAULT


Expand Down Expand Up @@ -60,4 +62,7 @@ def expression_to_value(expression: exp.Expression) -> Any:
return True
if expression.name == "OFF":
return False
return expression.name
raise MysqlError(
"Complex expressions in variables not supported yet",
code=ErrorCode.NOT_SUPPORTED_YET,
)
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ async def mysql_connector_conn(
connect: ConnectFixture,
) -> AsyncGenerator[MySQLConnectionAbstract, None]:
conn = await connect(user="levon_helm")
# Different versions of mysql-connector use various default collations.
# Execute the following query to ensure consistent test results across different versions.
await query(conn, "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci'")
try:
yield conn
finally:
Expand Down
15 changes: 10 additions & 5 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,12 @@ async def test_query_attributes(
),
(
"""
SELECT
/*+ SET_VAR(max_execution_time=2) */
x
SELECT
/*+ SET_VAR(max_execution_time=2) */
x
FROM (
SELECT
/*+ SET_VAR(max_execution_time=1) */
SELECT
/*+ SET_VAR(max_execution_time=1) */
@@max_execution_time AS x
) AS a
""",
Expand Down Expand Up @@ -839,6 +839,11 @@ async def test_commands(
),
("SET @foo = 'bar'", "User-defined variables not supported yet"),
("KILL 'abc'", "Invalid KILL connection ID"),
(
# pick a dynamic string session var
"SET init_connect='abc' in xyz",
"Complex expressions in variables not supported yet",
),
],
)
async def test_unsupported_commands(
Expand Down

0 comments on commit 18e6587

Please sign in to comment.