(
self,
pgq: PostgresQuery,
*,
prepare: bool | None = None,
binary: bool | None = None,
)
| 273 | yield from self._conn._prepared.maintain_gen(self._conn) |
| 274 | |
| 275 | def _maybe_prepare_gen( |
| 276 | self, |
| 277 | pgq: PostgresQuery, |
| 278 | *, |
| 279 | prepare: bool | None = None, |
| 280 | binary: bool | None = None, |
| 281 | ) -> PQGen[None]: |
| 282 | # Check if the query is prepared or needs preparing |
| 283 | prep, name = self._get_prepared(pgq, prepare) |
| 284 | if prep is Prepare.NO: |
| 285 | # The query must be executed without preparing |
| 286 | self._execute_send(pgq, binary=binary) |
| 287 | else: |
| 288 | # If the query is not already prepared, prepare it. |
| 289 | if prep is Prepare.SHOULD: |
| 290 | self._send_prepare(name, pgq) |
| 291 | if not self._conn._pipeline: |
| 292 | results = yield from execute(self._pgconn) |
| 293 | for result in results: |
| 294 | if result.status == FATAL_ERROR: |
| 295 | raise e.error_from_result(result, encoding=self._encoding) |
| 296 | # Then execute it. |
| 297 | self._send_query_prepared(name, pgq, binary=binary) |
| 298 | |
| 299 | # Update the prepare state of the query. |
| 300 | # If an operation requires to flush our prepared statements cache, |
| 301 | # it will be added to the maintenance commands to execute later. |
| 302 | key = self._conn._prepared.maybe_add_to_cache(pgq, prep, name) |
| 303 | |
| 304 | if self._conn._pipeline: |
| 305 | queued = None |
| 306 | if key is not None: |
| 307 | queued = (key, prep, name) |
| 308 | self._conn._pipeline.result_queue.append((self, queued)) |
| 309 | return |
| 310 | |
| 311 | # run the query |
| 312 | results = yield from execute(self._pgconn) |
| 313 | |
| 314 | if key is not None: |
| 315 | self._conn._prepared.validate(key, prep, name, results) |
| 316 | |
| 317 | self._check_results(results) |
| 318 | self._set_results(results) |
| 319 | |
| 320 | def _get_prepared( |
| 321 | self, pgq: PostgresQuery, prepare: bool | None = None |
no test coverage detected