summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarikg <InternalIce9>2015-01-08 19:44:24 -0500
committerAmjith Ramanujam <amjith.r@gmail.com>2015-01-10 00:27:05 -0800
commit7950b8a6ee5ea9feac6db2c335e7734cafc4e775 (patch)
treecdc1c8c6fcfcc66f31ca5ca29c889430a0f5692d
parent56f0da2ea19977ea0a13c2144271cf3261376f63 (diff)
maintain a history of queries and whether they were successful or not
-rwxr-xr-xpgcli/main.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/pgcli/main.py b/pgcli/main.py
index f9afc368..94c734c1 100755
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -33,6 +33,10 @@ except ImportError:
from getpass import getuser
from psycopg2 import OperationalError
+from collections import deque, namedtuple
+
+#Query tuples are used for maintaining history
+Query = namedtuple('Query', ['query', 'successful'])
class PGCli(object):
def __init__(self, force_passwd_prompt=False, never_passwd_prompt=False,
@@ -56,6 +60,8 @@ class PGCli(object):
self.logger = logging.getLogger(__name__)
self.initialize_logging()
+ self.query_history = []
+
def initialize_logging(self):
log_file = self.config.get('main', 'log_file')
@@ -163,6 +169,7 @@ class PGCli(object):
try:
logger.debug('sql: %r', document.text)
res = pgexecute.run(document.text)
+ successful = True
output = []
for rows, headers, status in res:
logger.debug("headers: %r", headers)
@@ -179,12 +186,16 @@ class PGCli(object):
logger.error("sql: %r, error: %r", document.text, e)
logger.error("traceback: %r", traceback.format_exc())
click.secho(str(e), err=True, fg='red')
+ successful = False
# Refresh the table names and column names if necessary.
if need_completion_refresh(document.text):
prompt = '%s> ' % pgexecute.dbname
completer.reset_completions()
refresh_completions(pgexecute, completer)
+
+ self.query_history.append(Query(document.text, successful))
+
except Exit:
print ('GoodBye!')
finally: # Reset the less opts back to original.