summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Walker <walker@pobox.com>2022-09-01 19:52:03 -0400
committerRoland Walker <walker@pobox.com>2022-09-01 19:54:14 -0400
commit2251a7f390a077b16f59eeb38555f2002427f5ed (patch)
tree58d94920c5c86fc1068de760397348325fa06139
parent09297b101fa7f5cb02016624533f00f4e5a8ab28 (diff)
avoid method on None in un/prettifyRW/prettify-exception-edge-cases
sqlglot returns None when the statement is only whitespace
-rw-r--r--changelog.md10
-rwxr-xr-xmycli/main.py4
2 files changed, 11 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index 3dbdc1f..a732e54 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,9 +1,17 @@
-1.26.1 (2022/09/01)
+TBD
===
Bug Fixes:
----------
+* better handle empty statements in un/prettify
+
+
+1.26.1 (2022/09/01)
+===================
+
+Bug Fixes:
+----------
* Require Python 3.7 in `setup.py`
diff --git a/mycli/main.py b/mycli/main.py
index 208572d..9cdcdd9 100755
--- a/mycli/main.py
+++ b/mycli/main.py
@@ -589,7 +589,7 @@ class MyCli(object):
statements = sqlglot.parse(text, read='mysql')
except Exception as e:
statements = []
- if len(statements) == 1:
+ if len(statements) == 1 and statements[0]:
pretty_text = statements[0].sql(pretty=True, pad=4, dialect='mysql')
else:
pretty_text = ''
@@ -603,7 +603,7 @@ class MyCli(object):
statements = sqlglot.parse(text, read='mysql')
except Exception as e:
statements = []
- if len(statements) == 1:
+ if len(statements) == 1 and statements[0]:
unpretty_text = statements[0].sql(pretty=False, dialect='mysql')
else:
unpretty_text = ''