MCPcopy
hub / github.com/andialbrecht/sqlparse / test_grouping_identifiers

Function test_grouping_identifiers

tests/test_grouping.py:61–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59
60
61def test_grouping_identifiers():
62 s = 'select foo.bar from "myscheme"."table" where fail. order'
63 parsed = sqlparse.parse(s)[0]
64 assert str(parsed) == s
65 assert isinstance(parsed.tokens[2], sql.Identifier)
66 assert isinstance(parsed.tokens[6], sql.Identifier)
67 assert isinstance(parsed.tokens[8], sql.Where)
68 s = 'select * from foo where foo.id = 1'
69 parsed = sqlparse.parse(s)[0]
70 assert str(parsed) == s
71 assert isinstance(parsed.tokens[-1].tokens[-1].tokens[0], sql.Identifier)
72 s = 'select * from (select "foo"."id" from foo)'
73 parsed = sqlparse.parse(s)[0]
74 assert str(parsed) == s
75 assert isinstance(parsed.tokens[-1].tokens[3], sql.Identifier)
76
77 for s in ["INSERT INTO `test` VALUES('foo', 'bar');",
78 "INSERT INTO `test` VALUES(1, 2), (3, 4), (5, 6);",
79 "INSERT INTO `test(a, b)` VALUES(1, 2), (3, 4), (5, 6);"]:
80 parsed = sqlparse.parse(s)[0]
81 types = [l.ttype for l in parsed.tokens if not l.is_whitespace]
82 assert types == [T.DML, T.Keyword, None, None, T.Punctuation]
83 assert isinstance(parsed.tokens[6], sql.Values)
84
85 s = "select 1.0*(a+b) as col, sum(c)/sum(d) from myschema.mytable"
86 parsed = sqlparse.parse(s)[0]
87 assert len(parsed.tokens) == 7
88 assert isinstance(parsed.tokens[2], sql.IdentifierList)
89 assert len(parsed.tokens[2].tokens) == 4
90 identifiers = list(parsed.tokens[2].get_identifiers())
91 assert len(identifiers) == 2
92 assert identifiers[0].get_alias() == "col"
93
94
95@pytest.mark.parametrize('s', [

Callers

nothing calls this directly

Calls 2

get_identifiersMethod · 0.80
get_aliasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…