From b66a89268b1dfc1db545d542ae235fb4e2ffb9a7 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 19 Feb 2020 09:49:38 -0800 Subject: [PATCH] Use sqlparse to strip comments before finding columns. --- setup.py | 1 + voussoirkit/sqlhelpers.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index b04e3b1..3e257f8 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ setuptools.setup( url='https://github.com/voussoir/voussoirkit', install_requires=[ 'pyperclip', + 'sqlparse', 'pywin32;platform_system=="Windows"', 'winshell;platform_system=="Windows"', ] diff --git a/voussoirkit/sqlhelpers.py b/voussoirkit/sqlhelpers.py index a24f4b0..901609c 100644 --- a/voussoirkit/sqlhelpers.py +++ b/voussoirkit/sqlhelpers.py @@ -1,3 +1,5 @@ +import re +import sqlparse import types def delete_filler(pairs): @@ -162,9 +164,8 @@ def listify(items): return output def _extract_create_table_statements(script): + script = sqlparse.format(script, strip_comments=True) for statement in script.split(';'): - statement = statement.strip() - statement = statement.strip('-') statement = statement.strip() if statement.lower().startswith('create table'): yield statement