MCPcopy
hub / github.com/dbcli/pgcli / execute_from_file

Method execute_from_file

pgcli/main.py:495–524  ·  view source on GitHub ↗
(self, pattern, **_)

Source from the content-addressed store, hash-verified

493 )
494
495 def execute_from_file(self, pattern, **_):
496 if not pattern:
497 message = "\\i: missing required argument"
498 return [(None, None, None, message, "", False, True)]
499 try:
500 with open(os.path.expanduser(pattern), encoding="utf-8") as f:
501 query = f.read()
502 except OSError as e:
503 return [(None, None, None, str(e), "", False, True)]
504
505 if self.destructive_warning:
506 if (
507 self.destructive_statements_require_transaction
508 and not self.pgexecute.valid_transaction()
509 and is_destructive(query, self.destructive_warning)
510 ):
511 message = "Destructive statements must be run within a transaction. Command execution stopped."
512 return [(None, None, None, message)]
513 destroy = confirm_destructive_query(query, self.destructive_warning, self.dsn_alias)
514 if destroy is False:
515 message = "Wise choice. Command execution stopped."
516 return [(None, None, None, message)]
517
518 on_error_resume = self.on_error == "RESUME"
519 return self.pgexecute.run(
520 query,
521 self.pgspecial,
522 on_error_resume=on_error_resume,
523 explain_mode=self.explain_mode,
524 )
525
526 def write_to_logfile(self, pattern, **_):
527 if not pattern:

Callers

nothing calls this directly

Calls 4

is_destructiveFunction · 0.85
valid_transactionMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected