| 340 | |
| 341 | |
| 342 | def _emit_where_token(ctx: SuggestContext) -> list[Suggestion]: |
| 343 | assert isinstance(ctx.token, Where) |
| 344 | # sqlparse groups all tokens from the where clause into a single token |
| 345 | # list. This means that token.value may be something like |
| 346 | # 'where foo > 5 and '. We need to look "inside" token.tokens to handle |
| 347 | # suggestions in complicated where clauses correctly. |
| 348 | # |
| 349 | # This logic also needs to look even deeper in to the WHERE clause. |
| 350 | # We recapitulate some transcoding suggestions here, but cannot |
| 351 | # recapitulate the entire logic of this function. |
| 352 | where_tokens = [x for x in ctx.token.tokens if x.ttype != sqlparse.tokens.Token.Text.Whitespace] |
| 353 | if transcoding_suggestion := _charset_suggestion(where_tokens): |
| 354 | return transcoding_suggestion |
| 355 | |
| 356 | original_text = ctx.text_before_cursor |
| 357 | prev_keyword, rewound_text = find_prev_keyword(ctx.text_before_cursor) |
| 358 | enum_suggestion = _enum_value_suggestion(original_text, ctx.full_text) |
| 359 | fallback = suggest_based_on_last_token(prev_keyword, rewound_text, None, ctx.full_text, ctx.identifier) |
| 360 | if enum_suggestion and _is_where_or_having(prev_keyword): |
| 361 | return [enum_suggestion] + fallback |
| 362 | return fallback |
| 363 | |
| 364 | |
| 365 | def _emit_binary_or_comma(ctx: SuggestContext) -> list[Suggestion]: |