From d9b717a12da7805d5a37b6b659300e449c42bd2f Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 19 Apr 2015 02:11:39 +0200 Subject: Improve detection of aliased identifiers (fixes #185). --- tests/test_grouping.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/test_grouping.py b/tests/test_grouping.py index b6edafe..5ade830 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -186,6 +186,11 @@ class TestGrouping(TestCaseBase): self.assertEqual(len(p.tokens), 1) self.assertEqual(p.tokens[0].get_alias(), 'foo') + def test_alias_returns_none(self): # see issue185 + p = sqlparse.parse('foo.bar')[0] + self.assertEqual(len(p.tokens), 1) + self.assertEqual(p.tokens[0].get_alias(), None) + def test_idlist_function(self): # see issue10 too p = sqlparse.parse('foo(1) x, bar')[0] self.assert_(isinstance(p.tokens[0], sql.IdentifierList)) -- cgit v1.2.1 From 621e1d84607a158491ce80c47814e51a8c366498 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 26 Jul 2015 10:38:54 +0200 Subject: Don't treat DECLARE within BEGIN blocks as relevant to split level (fixes #193). --- tests/test_regressions.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_regressions.py b/tests/test_regressions.py index e30ddf0..6da94dc 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -243,4 +243,15 @@ def test_null_with_as(): ' NULL AS c2', 'FROM t1' ]) - assert formatted == tformatted \ No newline at end of file + assert formatted == tformatted + + +def test_issue193_splitting_function(): + sql = """CREATE FUNCTION a(x VARCHAR(20)) RETURNS VARCHAR(20) +BEGIN + DECLARE y VARCHAR(20); + RETURN x; +END; +SELECT * FROM a.b;""" + splitted = sqlparse.split(sql) + assert len(splitted) == 2 -- cgit v1.2.1 From 8b5a957f4dad82fda0dc174538fdaf0860a9256a Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 26 Jul 2015 11:05:58 +0200 Subject: Recognize MSSQL temp tables and distinguish from MySQL comments (fixes #192). --- tests/test_parse.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/test_parse.py b/tests/test_parse.py index 857685b..6c9d6a6 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -293,3 +293,13 @@ def test_single_line_comments(sql): assert p.tokens[-1].ttype == T.Comment.Single +@pytest.mark.parametrize('sql', [ + 'foo', + '@foo', + '#foo', # see issue192 + '##foo' +]) +def test_names_and_special_names(sql): + p = sqlparse.parse(sql)[0] + assert len(p.tokens) == 1 + assert isinstance(p.tokens[0], sqlparse.sql.Identifier) -- cgit v1.2.1 From fb6b59dece40a608a1c6cf741a4ac6ee88d85d2f Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 26 Jul 2015 11:20:49 +0200 Subject: Ignore comments at beginning of statement when calling Statement.get_type (fixes #186). --- tests/test_regressions.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 6da94dc..ea8cd56 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -255,3 +255,9 @@ END; SELECT * FROM a.b;""" splitted = sqlparse.split(sql) assert len(splitted) == 2 + + +def test_issue186_get_type(): + sql = "-- comment\ninsert into foo" + p = sqlparse.parse(sql)[0] + assert p.get_type() == 'INSERT' -- cgit v1.2.1