From dbc9220a2b29725f94637607f8d8b00c762deb67 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 4 Sep 2016 16:36:12 +0300 Subject: [PATCH] Move requote_names from process_tokens.py to process_mysql.py --- demo/group-file.py | 4 ++-- demo/group-sql.py | 4 ++-- demo/parse-file.py | 3 ++- demo/parse-sql.py | 3 ++- scripts/mysql2sql | 3 ++- sqlconvert/process_mysql.py | 15 +++++++++++++++ sqlconvert/process_tokens.py | 16 +--------------- tests/test_stgrouper.py | 3 ++- tests/test_tokens.py | 2 +- 9 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 sqlconvert/process_mysql.py diff --git a/demo/group-file.py b/demo/group-file.py index 54d1cc2..e59ff45 100755 --- a/demo/group-file.py +++ b/demo/group-file.py @@ -3,8 +3,8 @@ from __future__ import print_function import sys from sqlconvert.print_tokens import print_tokens -from sqlconvert.process_tokens import requote_names, find_error, \ - StatementGrouper +from sqlconvert.process_mysql import requote_names +from sqlconvert.process_tokens import find_error, StatementGrouper def main(filename): diff --git a/demo/group-sql.py b/demo/group-sql.py index 25493d5..854a0d1 100755 --- a/demo/group-sql.py +++ b/demo/group-sql.py @@ -3,8 +3,8 @@ from __future__ import print_function import sys from sqlconvert.print_tokens import print_tokens -from sqlconvert.process_tokens import requote_names, find_error, \ - StatementGrouper +from sqlconvert.process_mysql import requote_names +from sqlconvert.process_tokens import find_error, StatementGrouper def main(*queries): diff --git a/demo/parse-file.py b/demo/parse-file.py index 34a99b7..bf65eec 100755 --- a/demo/parse-file.py +++ b/demo/parse-file.py @@ -4,7 +4,8 @@ from __future__ import print_function import sys from sqlparse import parse from sqlconvert.print_tokens import print_tokens -from sqlconvert.process_tokens import requote_names, find_error +from sqlconvert.process_mysql import requote_names +from sqlconvert.process_tokens import find_error def main(filename): diff --git a/demo/parse-sql.py b/demo/parse-sql.py index cb3f165..1cbe0a1 100755 --- a/demo/parse-sql.py +++ b/demo/parse-sql.py @@ -4,7 +4,8 @@ from __future__ import print_function import sys from sqlparse import parse from sqlconvert.print_tokens import print_tokens -from sqlconvert.process_tokens import requote_names, find_error +from sqlconvert.process_mysql import requote_names +from sqlconvert.process_tokens import find_error def main(*queries): diff --git a/scripts/mysql2sql b/scripts/mysql2sql index d3178e9..5ba8fd7 100755 --- a/scripts/mysql2sql +++ b/scripts/mysql2sql @@ -8,7 +8,8 @@ import sys from sqlparse.compat import text_type from sqlconvert.print_tokens import print_tokens -from sqlconvert.process_tokens import requote_names, StatementGrouper +from sqlconvert.process_mysql import requote_names +from sqlconvert.process_tokens import StatementGrouper from m_lib.defenc import default_encoding from m_lib.pbar.tty_pbar import ttyProgressBar diff --git a/sqlconvert/process_mysql.py b/sqlconvert/process_mysql.py new file mode 100644 index 0000000..b11eccb --- /dev/null +++ b/sqlconvert/process_mysql.py @@ -0,0 +1,15 @@ + +from sqlparse.tokens import Name + + +def requote_names(token_list): + """Remove backticks, quote non-lowercase identifiers""" + for token in token_list.flatten(): + if token.ttype is Name: + value = token.value + if (value[0] == "`") and (value[-1] == "`"): + value = value[1:-1] + if value.islower(): + token.normalized = token.value = value + else: + token.normalized = token.value = '"%s"' % value diff --git a/sqlconvert/process_tokens.py b/sqlconvert/process_tokens.py index 1e74ac9..0bbf94c 100644 --- a/sqlconvert/process_tokens.py +++ b/sqlconvert/process_tokens.py @@ -1,21 +1,7 @@ from sqlparse import parse from sqlparse.compat import PY3 -from sqlparse.tokens import Name, Error, Punctuation, Comment, Newline, \ - Whitespace - - -def requote_names(token_list): - """Remove backticks, quote non-lowercase identifiers""" - for token in token_list.flatten(): - if token.ttype is Name: - value = token.value - if (value[0] == "`") and (value[-1] == "`"): - value = value[1:-1] - if value.islower(): - token.normalized = token.value = value - else: - token.normalized = token.value = '"%s"' % value +from sqlparse.tokens import Error, Punctuation, Comment, Newline, Whitespace def find_error(token_list): diff --git a/tests/test_stgrouper.py b/tests/test_stgrouper.py index 3354b02..299ea6c 100755 --- a/tests/test_stgrouper.py +++ b/tests/test_stgrouper.py @@ -4,7 +4,8 @@ import unittest from sqlconvert.print_tokens import tlist2str -from sqlconvert.process_tokens import requote_names, StatementGrouper +from sqlconvert.process_mysql import requote_names +from sqlconvert.process_tokens import StatementGrouper from tests import main diff --git a/tests/test_tokens.py b/tests/test_tokens.py index da62e43..692121e 100755 --- a/tests/test_tokens.py +++ b/tests/test_tokens.py @@ -4,8 +4,8 @@ import unittest from sqlparse import parse -from sqlconvert.process_tokens import requote_names from sqlconvert.print_tokens import tlist2str +from sqlconvert.process_mysql import requote_names from tests import main -- 2.39.5