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)
| 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 | """ |