MCPcopy
hub / github.com/psycopg/psycopg / ph

Function ph

tests/_test_cursor.py:29–47  ·  view source on GitHub ↗

Change placeholders in a query from %s to $n if testing a raw cursor

(cur: Any, query: str)

Source from the content-addressed store, hash-verified

27
28
29def ph(cur: Any, query: str) -> str:
30 """Change placeholders in a query from %s to $n if testing a raw cursor"""
31 from psycopg.raw_cursor import RawCursorMixin
32
33 if not isinstance(cur, RawCursorMixin):
34 return query
35
36 if "%(" in query:
37 pytest.skip("RawCursor only supports positional placeholders")
38
39 n = 1
40
41 def s(m: re.Match[str]) -> str:
42 nonlocal n
43 rv = f"${n}"
44 n += 1
45 return rv
46
47 return re.sub(r"(?<!%)(%[bst])", s, query)
48
49
50def my_row_factory(

Callers 15

workFunction · 0.85
workFunction · 0.85
test_query_paramsFunction · 0.85
test_close_no_clobberFunction · 0.85
test_execute_reuseFunction · 0.85
test_executemanyFunction · 0.85
test_fetchoneFunction · 0.85
test_fetchmanyFunction · 0.85
test_fetchallFunction · 0.85
test_nextsetFunction · 0.85
test_no_resultFunction · 0.85
test_iterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected