diff options
author | Darik Gamble <darik.gamble@gmail.com> | 2015-01-26 08:05:39 -0500 |
---|---|---|
committer | Darik Gamble <darik.gamble@gmail.com> | 2015-01-26 08:05:39 -0500 |
commit | 3abfde4003abbde943f960a99211931a8f95b04b (patch) | |
tree | c1ba152888760a7ff7e9d8926995ad6dbc197d0d | |
parent | 9ff2aa485489d35a0bfb936feb42786c45a9faa5 (diff) |
detect changes to the search_path and refresh accordingly
-rwxr-xr-x | pgcli/main.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/pgcli/main.py b/pgcli/main.py index 58160697..f47f7888 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -214,6 +214,12 @@ class PGCli(object): end = time() total += end - start mutating = mutating or is_mutating(status) + + if need_search_path_refresh(document.text, status): + logger.debug('Refreshing search path') + completer.set_search_path(pgexecute.search_path()) + logger.debug('Search path: %r', completer.search_path) + except KeyboardInterrupt: # Restart connection to the database pgexecute.connect() @@ -332,6 +338,22 @@ def need_completion_refresh(sql): except Exception: return False +def need_search_path_refresh(sql, status): + # note that sql may be a multi-command query, but status belongs to an + # individual query, since pgexecute handles splitting up multi-commands + try: + status = status.split()[0] + if status.lower() == 'set': + # Since sql could be a multi-line query, it's hard to robustly + # pick out the variable name that's been set. Err on the side of + # false positives here, since the worst case is we refresh the + # search path when it's not necessary + return 'search_path' in sql.lower() + else: + return False + except Exception: + return False + def is_mutating(status): """Determines if the statement is mutating based on the status.""" if not status: |