From 106c6c7bf889b0db5fe85eba31f3f7f6b52a0895 Mon Sep 17 00:00:00 2001 From: Irina Truong Date: Fri, 26 Jun 2020 13:39:31 -0700 Subject: Fix for #1193 list index out of range on sql comment. --- changelog.rst | 1 + pgcli/packages/parseutils/__init__.py | 2 +- pgcli/pgexecute.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/changelog.rst b/changelog.rst index e6f162a8..f2510394 100644 --- a/changelog.rst +++ b/changelog.rst @@ -13,6 +13,7 @@ Bug fixes: ---------- * Minor typo fixes in `pgclirc`. (Thanks: `anthonydb`_) +* Fix for list index out of range when executing commands from a file (#1193). (Thanks: `Irina Truong`_) 3.0.0 ===== diff --git a/pgcli/packages/parseutils/__init__.py b/pgcli/packages/parseutils/__init__.py index 9bfff73b..a11e7bf2 100644 --- a/pgcli/packages/parseutils/__init__.py +++ b/pgcli/packages/parseutils/__init__.py @@ -4,7 +4,7 @@ import sqlparse def query_starts_with(query, prefixes): """Check if the query starts with any item from *prefixes*.""" prefixes = [prefix.lower() for prefix in prefixes] - formatted_sql = sqlparse.format(query.lower(), strip_comments=True) + formatted_sql = sqlparse.format(query.lower(), strip_comments=True).strip() return bool(formatted_sql) and formatted_sql.split()[0] in prefixes diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index 776c9628..6f7bd715 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -373,9 +373,9 @@ class PGExecute(object): for sql in sqlparse.split(statement): # Remove spaces, eol and semi-colons. sql = sql.rstrip(";") + sql = sqlparse.format(sql, strip_comments=True).strip() if not sql: continue - try: if pgspecial: # \G is treated specially since we have to set the expanded output. -- cgit v1.2.3