from __future__ import annotations def quote_ident(value: str) -> str: return "`" + value.replace("`", "``") + "`" def sql_string(value: str) -> str: return "'" + value.replace("'", "''") + "'" def split_sql(sql: str) -> list[str]: statements: list[str] = [] current: list[str] = [] in_single_quote = False in_double_quote = False previous = "" for char in sql: if char == "'" and not in_double_quote and previous != "\\": in_single_quote = not in_single_quote elif char == '"' and not in_single_quote and previous != "\\": in_double_quote = not in_double_quote if char == ";" and not in_single_quote and not in_double_quote: statement = "".join(current).strip() if statement: statements.append(statement) current = [] else: current.append(char) previous = char statement = "".join(current).strip() if statement: statements.append(statement) return statements