Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/wren/src/wren/connector/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def query(self, sql: str, limit: int | None = None) -> pa.Table:
limit = _coerce_limit(limit)
if limit is not None:
sql = _apply_limit(sql, limit)
else:
# Unlimited path: strip trailing terminators so client-pasted SQL
# matches EXPLAIN / limit composition.
sql = strip_trailing_semicolon(sql)
with closing(self.connection.cursor()) as cursor:
cursor.execute(sql)
return _build_mysql_arrow_table(cursor)
Expand Down
44 changes: 44 additions & 0 deletions core/wren/tests/unit/test_mysql_semicolon_unlimited.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""MySQL unlimited query path strips trailing semicolon (mocked)."""

from __future__ import annotations

from unittest.mock import MagicMock

import pytest

from wren.connector.mysql import MySqlConnector

pytestmark = pytest.mark.unit


def _make_connector() -> tuple[MySqlConnector, MagicMock]:
connector = MySqlConnector.__new__(MySqlConnector)
cursor = MagicMock()
cursor.description = (("x", None, None, None, None, None, None),)
cursor.fetchall.return_value = ((1,),)
conn = MagicMock()
conn.cursor.return_value = cursor
connector.connection = conn
return connector, cursor


def test_query_strips_semicolon_when_unlimited(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
"wren.connector.mysql._build_mysql_arrow_table",
lambda cursor: object(),
)
connector, cursor = _make_connector()
connector.query("SELECT 1;")
cursor.execute.assert_called_once_with("SELECT 1")


def test_query_limit_path_still_strips_via_apply_limit(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
"wren.connector.mysql._build_mysql_arrow_table",
lambda cursor: object(),
)
connector, cursor = _make_connector()
connector.query("SELECT 1;", limit=2)
sent = cursor.execute.call_args[0][0]
assert "LIMIT 2" in sent
assert not sent.rstrip().endswith(";")
Loading