summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarik Gamble <darik.gamble.spam@gmail.com>2015-10-26 08:29:10 -0400
committerDarik Gamble <darik.gamble@gmail.com>2015-10-28 10:58:28 -0400
commitedcc5c8a2d9a2589f81a2a1fb037240a65d94fb8 (patch)
tree3b32218c4edfad6cae7122221df467ebe744e8f3
parent6df33e959d7c9122e28e5aa6a778b6766feab85f (diff)
pgexecute.run returns two extra tuple elements: query, and success
-rw-r--r--pgcli/pgexecute.py13
-rw-r--r--tests/utils.py2
2 files changed, 9 insertions, 6 deletions
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py
index 326fb123..2210058b 100644
--- a/pgcli/pgexecute.py
+++ b/pgcli/pgexecute.py
@@ -52,6 +52,7 @@ def register_json_typecasters(conn, loads_fn):
return available
+
def register_hstore_typecaster(conn):
"""
Instead of using register_hstore() which converts hstore into a python
@@ -67,6 +68,7 @@ def register_hstore_typecaster(conn):
except Exception:
pass
+
class PGExecute(object):
# The boolean argument to the current_schemas function indicates whether
@@ -235,13 +237,13 @@ class PGExecute(object):
execute.
:return: Generator yielding tuples containing
- (title, rows, headers, status)
+ (title, rows, headers, status, query, success)
"""
# Remove spaces and EOL
statement = statement.strip()
if not statement: # Empty string
- yield (None, None, None, None)
+ yield (None, None, None, None, statement, False)
# Split the sql into separate queries and run each one.
for sql in sqlparse.split(statement):
@@ -255,13 +257,13 @@ class PGExecute(object):
cur = self.conn.cursor()
try:
for result in pgspecial.execute(cur, sql):
- yield result
+ yield result + (sql, True)
continue
except special.CommandNotFound:
pass
# Not a special command, so execute as normal sql
- yield self.execute_normal_sql(sql)
+ yield self.execute_normal_sql(sql) + (sql, True)
except psycopg2.DatabaseError as e:
_logger.error("sql: %r, error: %r", sql, e)
_logger.error("traceback: %r", traceback.format_exc())
@@ -272,12 +274,13 @@ class PGExecute(object):
# specification
raise
- yield None, None, None, exception_formatter(e)
+ yield None, None, None, exception_formatter(e), sql, False
if not on_error_resume:
break
def execute_normal_sql(self, split_sql):
+ """Returns tuple (title, rows, headers, status)"""
_logger.debug('Regular sql statement. sql: %r', split_sql)
cur = self.conn.cursor()
cur.execute(split_sql)
diff --git a/tests/utils.py b/tests/utils.py
index d7d5993d..1f515add 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -65,7 +65,7 @@ def run(executor, sql, join=False, expanded=False, pgspecial=None,
results = executor.run(sql, pgspecial, exception_formatter)
formatted = []
- for title, rows, headers, status in results:
+ for title, rows, headers, status, sql, success in results:
formatted.extend(format_output(title, rows, headers, status, 'psql',
expanded=expanded))
if join: