MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / parse_partial_identifier

Function parse_partial_identifier

mssqlcli/packages/parseutils/utils.py:119–138  ·  view source on GitHub ↗

Attempt to parse a (partially typed) word as an identifier word may include a schema qualification, like `schema_name.partial_name` or `schema_name.` There may also be unclosed quotation marks, like `"schema`, or `schema."partial_name` :param word: string representing a (partially

(word)

Source from the content-addressed store, hash-verified

117
118
119def parse_partial_identifier(word):
120 """Attempt to parse a (partially typed) word as an identifier
121
122 word may include a schema qualification, like `schema_name.partial_name`
123 or `schema_name.` There may also be unclosed quotation marks, like
124 `"schema`, or `schema."partial_name`
125
126 :param word: string representing a (partially complete) identifier
127 :return: sqlparse.sql.Identifier, or None
128 """
129
130 p = sqlparse.parse(word)[0]
131 n_tok = len(p.tokens)
132 if n_tok == 1 and isinstance(p.tokens[0], Identifier):
133 return p.tokens[0]
134 if p.token_next_by(m=(Error, '"'))[1]:
135 # An unmatched double quote, e.g. '"foo', 'foo."', or 'foo."bar'
136 # Close the double quote, then reparse
137 return parse_partial_identifier(word + '"')
138 return None

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected