HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
sql: a MySQL statement's own LIMIT offset, count is respected (#486)
Rudy Mizrahi Celekli0d6a473a19d5
diff --git a/gateway/sql_plane.py b/gateway/sql_plane.pyindex ef6a073c..b39dccc8 100644--- a/gateway/sql_plane.py+++ b/gateway/sql_plane.py@@ -102,7 +102,8 @@ def check_readonly(sql: str) -> str:return raw-_LIMIT_TAIL = re.compile(r"\blimit\s+\d+\s*(?:offset\s+\d+\s*)?$", re.I)+# `LIMIT n`, `LIMIT n OFFSET m`, and MySQL's `LIMIT offset, count`.+_LIMIT_TAIL = re.compile(r"\blimit\s+\d+\s*(?:(?:offset\s+\d+|,\s*\d+)\s*)?$", re.I)def with_limit(sql: str, max_rows: int) -> tuple[str, bool]:diff --git a/gateway/tests/test_sql_plane.py b/gateway/tests/test_sql_plane.pyindex e8ae8e5a..4f6bd241 100644--- a/gateway/tests/test_sql_plane.py+++ b/gateway/tests/test_sql_plane.py@@ -111,6 +111,19 @@ def test_limit_with_offset_is_respected():assert not added+def test_mysqls_limit_offset_count_is_respected():+ """MySQL spells an offset as `LIMIT 5, 10`. The tail check knew only `LIMIT n [OFFSET m]`, so it+ appended a second LIMIT after this one, a syntax error, and the query never ran."""+ for sql in ("SELECT * FROM t LIMIT 5, 10", "SELECT * FROM t ORDER BY x limit 5 ,10"):+ out, added = with_limit(sql, 500)+ assert not added and out == sql+++def test_a_comma_inside_the_query_is_not_read_as_a_limit():+ out, added = with_limit("SELECT a, b FROM (SELECT a, b FROM t LIMIT 5, 10) s", 500)+ assert added and out.rstrip().endswith("LIMIT 500")++def test_limit_inside_a_subquery_does_not_count_as_the_outer_one():"""The outer query is unbounded and must still be capped."""out, added = with_limit("SELECT * FROM (SELECT * FROM t LIMIT 10) s", 500)