summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlaixintao <laixintaoo@gmail.com>2020-06-28 10:12:17 +0800
committerGitHub <noreply@github.com>2020-06-28 10:12:17 +0800
commit77414aa9e75f89cca9d248d4c0f3b9f1959007c8 (patch)
tree3dff64c1326922548cb4b1042350cf1bb99a9b4b
parent0c24e8bda226f3dbd6ccb0381515a9c903847249 (diff)
parent106c6c7bf889b0db5fe85eba31f3f7f6b52a0895 (diff)
Merge pull request #1194 from dbcli/j-bennet/fix-sql-comment
J bennet/fix sql comment
-rw-r--r--changelog.rst1
-rw-r--r--pgcli/packages/parseutils/__init__.py2
-rw-r--r--pgcli/pgexecute.py2
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.