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

Function extract_column_names

mssqlcli/packages/parseutils/ctes.py:115–129  ·  view source on GitHub ↗
(parsed)

Source from the content-addressed store, hash-verified

113
114
115def extract_column_names(parsed):
116 # Find the first DML token to check if it's a SELECT or INSERT/UPDATE/DELETE
117 idx, tok = parsed.token_next_by(t=DML)
118 tok_val = tok and tok.value.lower()
119
120 if tok_val in ('insert', 'update', 'delete'):
121 # Jump ahead to the RETURNING clause where the list of column names is
122 idx, tok = parsed.token_next_by(idx, (Keyword, 'returning'))
123 elif not tok_val == 'select':
124 # Must be invalid CTE
125 return ()
126
127 # The next token should be either a column name, or a list of column names
128 idx, tok = parsed.token_next(idx, skip_ws=True, skip_cm=True)
129 return tuple(t.get_name() for t in _identifiers(tok))
130
131
132def token_start_pos(tokens, idx):

Callers 1

get_cte_from_tokenFunction · 0.70

Calls 1

_identifiersFunction · 0.85

Tested by

no test coverage detected