Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.8 KB
Raw Blame
"""Check the SQLAlchemy quoting assumptions used by the native rule controls."""

import pytest
from sqlalchemy import ColumnClause, column, create_engine, select
from sqlalchemy.sql import quoted_name


@pytest.mark.parametrize(
    ("make_column", "expected"),
    [
        pytest.param(lambda name: column(name), "1 + 2", id="default-quoting"),
        pytest.param(
            lambda name: ColumnClause(name, None, False),
            "1 + 2",
            id="explicit-false",
        ),
        pytest.param(
            lambda name: column(quoted_name(name, True)),
            "1 + 2",
            id="forced-quoting",
        ),
        pytest.param(
            lambda name: column(name, **{"is_literal": True}),
            3,
            id="unpacked-keywords",
        ),
        pytest.param(
            lambda name: column(name, *(None, True)),
            3,
            id="unpacked-positionals",
        ),
        pytest.param(
            lambda name: column(quoted_name(name, False)),
            3,
            id="quoting-disabled-by-name",
        ),
        pytest.param(
            lambda name: column(quoted_name(name, False), is_literal=False),
            3,
            id="literal-false-does-not-force-quoting",
        ),
        pytest.param(
            lambda name: column(name, is_literal=[False]),
            3,
            id="truthy-container",
        ),
    ],
)
def test_column_quoting_controls_sql_execution(make_column, expected):
    engine = create_engine("sqlite://")
    try:
        # Isolate each quoting case from compiled-statement cache reuse.
        with engine.connect().execution_options(compiled_cache=None) as conn:
            result = conn.execute(select(make_column("1 + 2"))).scalar_one()
        assert result == expected
    finally:
        engine.dispose()