summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pgcli/pgbuffer.py1
-rw-r--r--pgcli/pgexecute.py12
-rw-r--r--tests/test_pgexecute.py7
3 files changed, 20 insertions, 0 deletions
diff --git a/pgcli/pgbuffer.py b/pgcli/pgbuffer.py
index bf1a10eb..7e89542d 100644
--- a/pgcli/pgbuffer.py
+++ b/pgcli/pgbuffer.py
@@ -33,6 +33,7 @@ def _multiline_exception(text):
return (
text.startswith("\\")
or text.endswith(r"\e") # Special Command
+ or text.endswith(r"\G") # Special Command
or _is_complete(text) # Ended with \e which should launch the editor
or (text == "exit") # A complete SQL command
or (text == "quit") # Exit doesn't need semi-colon
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py
index ad5ed4a3..2dbfea65 100644
--- a/pgcli/pgexecute.py
+++ b/pgcli/pgexecute.py
@@ -213,6 +213,7 @@ class PGExecute(object):
self.server_version = None
self.extra_args = None
self.connect(database, user, password, host, port, dsn, **kwargs)
+ self.reset_expanded = None
def copy(self):
"""Returns a clone of the current executor."""
@@ -378,6 +379,13 @@ class PGExecute(object):
try:
if pgspecial:
+ # \G is treated specially since we have to set the expanded output.
+ if sql.endswith('\\G'):
+ if not pgspecial.expanded_output:
+ pgspecial.expanded_output = True
+ self.reset_expanded = True
+ sql = sql[:-2].strip()
+
# First try to run each query as special
_logger.debug("Trying a pgspecial command. sql: %r", sql)
try:
@@ -411,6 +419,10 @@ class PGExecute(object):
if not on_error_resume:
break
+ finally:
+ if self.reset_expanded:
+ pgspecial.expanded_output = False
+ self.reset_expanded = None
def _must_raise(self, e):
"""Return true if e is an error that should not be caught in ``run``.
diff --git a/tests/test_pgexecute.py b/tests/test_pgexecute.py
index 55d7f548..c42bcee3 100644
--- a/tests/test_pgexecute.py
+++ b/tests/test_pgexecute.py
@@ -86,6 +86,13 @@ def test_bools_are_treated_as_strings(executor):
SELECT 1"""
)
+@dbtest
+def test_expanded_slash_G(executor, pgspecial):
+ # Tests whether we reset the expanded output after a \G.
+ run(executor, """create table test(a boolean)""")
+ run(executor, """insert into test values(True)""")
+ results = run(executor, """select * from test \G""", pgspecial=pgspecial)
+ assert pgspecial.expanded_output == False
@dbtest
def test_schemata_table_views_and_columns_query(executor):