From 3f310f5070d45852afda29ed50ba656ff1cb7465 Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Thu, 25 Aug 2016 20:53:39 +0200 Subject: Add more placeholders to prompt --- pgcli/main.py | 3 +++ pgcli/pgexecute.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/pgcli/main.py b/pgcli/main.py index 431e282f..4d29e0aa 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -682,6 +682,9 @@ class PGCli(object): string = string.replace('\\u', self.pgexecute.user or '(none)') string = string.replace('\\h', self.pgexecute.host or '(none)') string = string.replace('\\d', self.pgexecute.dbname or '(none)') + string = string.replace('\\p', str(self.pgexecute.port) or '(none)') + string = string.replace('\\i', str(self.pgexecute.pid) or '(none)') + string = string.replace('\\#', "#" if (self.pgexecute.superuser) else ">") string = string.replace('\\n', "\n") return string diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index 9552ce64..8538cd88 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -136,6 +136,9 @@ class PGExecute(object): host = (host or self.host) port = (port or self.port) dsn = (dsn or self.dsn) + pid = -1 + superuser = False + print("dsn: %s" % dsn) if dsn: if password: dsn = "{0} password={1}".format(dsn, password) @@ -154,6 +157,11 @@ class PGExecute(object): password=unicode2utf8(password), host=unicode2utf8(host), port=unicode2utf8(port)) + + cursor = conn.cursor() + + superuser = self._select_one(cursor, "select current_setting('is_superuser')::bool")[0] + pid = self._select_one(cursor, 'select pg_backend_pid()')[0] conn.set_client_encoding('utf8') if hasattr(self, 'conn'): self.conn.close() @@ -164,6 +172,8 @@ class PGExecute(object): self.password = password self.host = host self.port = port + self.pid = pid + self.superuser = superuser register_date_typecasters(conn) register_json_typecasters(self.conn, self._json_typecaster) -- cgit v1.2.3