from typing import Any from test_fixtures.mysql import MySQLConnection def placeholders(values: list[Any]) -> str: """Comma-separated %s string for a SQL IN clause.""" return ",".join(["%s"] * len(values)) def discover_single_pk(db: MySQLConnection, table_name: str) -> str: """Return the primary-key column name for a single-column-PK table. Safe to interpolate into SQL because the value comes from INFORMATION_SCHEMA, not from test input. """ rows = db.fetchall( """ SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s AND COLUMN_KEY = 'PRI' ORDER BY ORDINAL_POSITION """, (table_name,), ) pk_cols = [r["COLUMN_NAME"] for r in rows] assert len(pk_cols) == 1, f"Expected single-column primary key on {table_name}, got: {pk_cols}" return str(pk_cols[0])