MCPcopy
hub / github.com/dbcli/pgcli / __init__

Method __init__

pgcli/packages/sqlcompletion.py:52–84  ·  view source on GitHub ↗
(self, full_text, text_before_cursor)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected