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

Method __init__

mssqlcli/packages/sqlcompletion.py:58–95  ·  view source on GitHub ↗
(self, full_text, text_before_cursor)

Source from the content-addressed store, hash-verified

56
57class SqlStatement:
58 def __init__(self, full_text, text_before_cursor):
59 self.identifier = None
60 self.word_before_cursor = word_before_cursor = last_word(
61 text_before_cursor, include='many_punctuations')
62 full_text = _strip_named_query(full_text)
63 text_before_cursor = _strip_named_query(text_before_cursor)
64
65 full_text, text_before_cursor, self.local_tables = \
66 isolate_query_ctes(full_text, text_before_cursor)
67
68 self.text_before_cursor_including_last_word = text_before_cursor
69
70 # If we've partially typed a word then word_before_cursor won't be an
71 # empty string. In that case we want to remove the partially typed
72 # string before sending it to the sqlparser. Otherwise the last token
73 # will always be the partially typed string which renders the smart
74 # completion useless because it will always return the list of
75 # keywords as completion.
76 if self.word_before_cursor:
77 if word_before_cursor[-1] == '(' or word_before_cursor[0] == '\\':
78 parsed = sqlparse.parse(text_before_cursor)
79 else:
80 text_before_cursor = text_before_cursor[:-
81 len(word_before_cursor)]
82 parsed = sqlparse.parse(text_before_cursor)
83 self.identifier = parse_partial_identifier(word_before_cursor)
84 else:
85 parsed = sqlparse.parse(text_before_cursor)
86
87 full_text, text_before_cursor, parsed = \
88 _split_multiple_statements(full_text, text_before_cursor, parsed)
89
90 self.full_text = full_text
91 self.text_before_cursor = text_before_cursor
92 self.parsed = parsed
93
94 self.last_token = parsed.token_prev(len(parsed.tokens))[1] \
95 if parsed and parsed.token_prev(len(parsed.tokens))[1] else ''
96
97 def is_insert(self):
98 return self.parsed.token_first().value.lower() == 'insert'

Callers

nothing calls this directly

Calls 5

last_wordFunction · 0.90
isolate_query_ctesFunction · 0.90
parse_partial_identifierFunction · 0.90
_strip_named_queryFunction · 0.85

Tested by

no test coverage detected