MCPcopy Index your code
hub / github.com/dbcli/pgcli / _check_ongoing_transaction_and_allow_quitting

Method _check_ongoing_transaction_and_allow_quitting

pgcli/main.py:929–957  ·  view source on GitHub ↗

Return whether we can really quit, possibly by asking the user to confirm so if there is an ongoing transaction.

(self)

Source from the content-addressed store, hash-verified

927 return query
928
929 def _check_ongoing_transaction_and_allow_quitting(self):
930 """Return whether we can really quit, possibly by asking the
931 user to confirm so if there is an ongoing transaction.
932 """
933 if not self.pgexecute.valid_transaction():
934 return True
935 while 1:
936 try:
937 choice = click.prompt(
938 "A transaction is ongoing. Choose `c` to COMMIT, `r` to ROLLBACK, `a` to abort exit, `force` to exit anyway.",
939 default="a",
940 )
941 except click.Abort:
942 # Print newline if user aborts with `^C`, otherwise
943 # pgcli's prompt will be printed on the same line
944 # (just after the confirmation prompt).
945 click.echo(None, err=False)
946 choice = "a"
947 choice = choice.lower()
948 if choice == "a":
949 return False # do not quit
950 if choice == "force":
951 return True # quit anyway
952 if choice == "c":
953 query = self.execute_command("commit")
954 return query.successful # quit only if query is successful
955 if choice == "r":
956 query = self.execute_command("rollback")
957 return query.successful # quit only if query is successful
958
959 def run_cli(self):
960 logger = self.logger

Callers 1

run_cliMethod · 0.95

Calls 3

execute_commandMethod · 0.95
valid_transactionMethod · 0.80
echoMethod · 0.80

Tested by

no test coverage detected