Generator to send a command and receive the result to the backend. Only used to implement internal commands such as "commit", with eventual arguments bound client-side. The cursor can do more complex stuff.
(
self, command: QueryNoTemplate, result_format: pq.Format = TEXT
)
| 443 | return conn |
| 444 | |
| 445 | def _exec_command( |
| 446 | self, command: QueryNoTemplate, result_format: pq.Format = TEXT |
| 447 | ) -> PQGen[PGresult | None]: |
| 448 | """ |
| 449 | Generator to send a command and receive the result to the backend. |
| 450 | |
| 451 | Only used to implement internal commands such as "commit", with eventual |
| 452 | arguments bound client-side. The cursor can do more complex stuff. |
| 453 | """ |
| 454 | self._check_connection_ok() |
| 455 | |
| 456 | if isinstance(command, str): |
| 457 | command = command.encode(self.pgconn._encoding) |
| 458 | elif isinstance(command, Composable): |
| 459 | command = command.as_bytes(self) |
| 460 | |
| 461 | if self._pipeline: |
| 462 | cmd = partial( |
| 463 | self.pgconn.send_query_params, |
| 464 | command, |
| 465 | None, |
| 466 | result_format=result_format, |
| 467 | ) |
| 468 | self._pipeline.command_queue.append(cmd) |
| 469 | self._pipeline.result_queue.append(None) |
| 470 | return None |
| 471 | |
| 472 | # Unless needed, use the simple query protocol, e.g. to interact with |
| 473 | # pgbouncer. In pipeline mode we always use the advanced query protocol |
| 474 | # instead, see #350 |
| 475 | if result_format == TEXT: |
| 476 | self.pgconn.send_query(command) |
| 477 | else: |
| 478 | self.pgconn.send_query_params(command, None, result_format=result_format) |
| 479 | |
| 480 | result: PGresult = (yield from generators.execute(self.pgconn))[-1] |
| 481 | if result.status != COMMAND_OK and result.status != TUPLES_OK: |
| 482 | if result.status == FATAL_ERROR: |
| 483 | raise e.error_from_result(result, encoding=self.pgconn._encoding) |
| 484 | else: |
| 485 | raise e.InterfaceError( |
| 486 | f"unexpected result {pq.ExecStatus(result.status).name}" |
| 487 | f" from command {command.decode()!r}" |
| 488 | ) |
| 489 | return result |
| 490 | |
| 491 | def _deallocate(self, name: bytes | None) -> PQGen[None]: |
| 492 | """ |
no test coverage detected