MCPcopy
hub / github.com/psycopg/psycopg / convert

Method convert

psycopg/psycopg/_queries.py:59–92  ·  view source on GitHub ↗

Set up the query and parameters to convert. The results of this function can be obtained accessing the object attributes (`query`, `params`, `types`, `formats`).

(self, query: Query, vars: Params | None)

Source from the content-addressed store, hash-verified

57 self._order: list[str] | None = None
58
59 def convert(self, query: Query, vars: Params | None) -> None:
60 """
61 Set up the query and parameters to convert.
62
63 The results of this function can be obtained accessing the object
64 attributes (`query`, `params`, `types`, `formats`).
65 """
66 if isinstance(query, Template):
67 return self._convert_template(query, vars)
68
69 query = self._ensure_bytes(query)
70
71 if vars is not None:
72 # Avoid caching queries extremely long or with a huge number of
73 # parameters. They are usually generated by ORMs and have poor
74 # cacheablility (e.g. INSERT ... VALUES (...), (...) with varying
75 # numbers of tuples.
76 # see https://github.com/psycopg/psycopg/discussions/628
77 if (
78 len(query) <= MAX_CACHED_STATEMENT_LENGTH
79 and len(vars) <= MAX_CACHED_STATEMENT_PARAMS
80 ):
81 f: _Query2Pg = _query2pg
82 else:
83 f = _query2pg_nocache
84
85 self.query, self._want_formats, self._order, self._parts = f(
86 query, self._tx.encoding
87 )
88 else:
89 self.query = query
90 self._want_formats = self._order = None
91
92 self.dump(vars)
93
94 def dump(self, vars: Params | None) -> None:
95 """

Callers 7

test_pg_query_seqFunction · 0.95
test_pg_query_mapFunction · 0.95
test_pq_query_badtypeFunction · 0.95
test_pq_query_badprogFunction · 0.95
_convert_queryMethod · 0.45

Calls 4

_convert_templateMethod · 0.95
_ensure_bytesMethod · 0.95
dumpMethod · 0.95
fFunction · 0.50

Tested by 6

test_pg_query_seqFunction · 0.76
test_pg_query_mapFunction · 0.76
test_pq_query_badtypeFunction · 0.76
test_pq_query_badprogFunction · 0.76