MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / replace

Method replace

lib/sqlalchemy/sql/compiler.py:7953–7976  ·  view source on GitHub ↗
(m)

Source from the content-addressed store, hash-verified

7951 d["_none"] = d[None] # type: ignore[index]
7952
7953 def replace(m):
7954 name = m.group(2)
7955 if name in d:
7956 effective_schema = d[name]
7957 else:
7958 if name in (None, "_none"):
7959 raise exc.InvalidRequestError(
7960 "schema translate map which previously had `None` "
7961 "present as a key now no longer has it present; don't "
7962 "know how to apply schema for compiled statement. "
7963 "Please use consistent keys in successive "
7964 "schema_translate_map dictionaries."
7965 )
7966 effective_schema = name
7967
7968 if not effective_schema:
7969 effective_schema = self.dialect.default_schema_name
7970 if not effective_schema:
7971 # TODO: no coverage here
7972 raise exc.CompileError(
7973 "Dialect has no default schema name; can't "
7974 "use None as dynamic schema target."
7975 )
7976 return self.quote_schema(effective_schema)
7977
7978 return re.sub(r"(__\[SCHEMA_([^\]]+)\])", replace, statement)
7979

Callers 6

post_process_textMethod · 0.45
escape_literal_columnMethod · 0.45
apply_placeholdersMethod · 0.45
_escape_identifierMethod · 0.45
_unescape_identifierMethod · 0.45

Calls 1

quote_schemaMethod · 0.95

Tested by

no test coverage detected