(
self, action: LiteralString, xid: Xid | str | None
)
| 663 | yield from self._pipeline._sync_gen() |
| 664 | |
| 665 | def _tpc_finish_gen( |
| 666 | self, action: LiteralString, xid: Xid | str | None |
| 667 | ) -> PQGen[None]: |
| 668 | fname = f"tpc_{action.lower()}()" |
| 669 | if xid is None: |
| 670 | if not self._tpc: |
| 671 | raise e.ProgrammingError( |
| 672 | f"{fname} without xid must must be" |
| 673 | " called inside a two-phase transaction" |
| 674 | ) |
| 675 | xid = self._tpc[0] |
| 676 | else: |
| 677 | if self._tpc: |
| 678 | raise e.ProgrammingError( |
| 679 | f"{fname} with xid must must be called" |
| 680 | " outside a two-phase transaction" |
| 681 | ) |
| 682 | if not isinstance(xid, Xid): |
| 683 | xid = Xid.from_string(xid) |
| 684 | |
| 685 | if self._tpc and not self._tpc[1]: |
| 686 | meth: Callable[[], PQGen[None]] |
| 687 | meth = getattr(self, f"_{action.lower()}_gen") |
| 688 | self._tpc = None |
| 689 | yield from meth() |
| 690 | else: |
| 691 | yield from self._exec_command( |
| 692 | SQL("{} PREPARED {}").format(SQL(action), str(xid)) |
| 693 | ) |
| 694 | self._tpc = None |
| 695 | |
| 696 | def _check_tpc(self) -> None: |
| 697 | """Raise NotSupportedError if TPC is not supported.""" |
no test coverage detected