From c36336afc587287eefdc20071cff7eddf01a41d3 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sun, 2 Mar 2025 14:50:55 +0000 Subject: [PATCH 1/2] Do not escape the upper case names --- litecli/sqlcompleter.py | 2 +- tests/test_smart_completion_public_schema_only.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/litecli/sqlcompleter.py b/litecli/sqlcompleter.py index a8a5a1e..1309f9b 100644 --- a/litecli/sqlcompleter.py +++ b/litecli/sqlcompleter.py @@ -258,7 +258,7 @@ def __init__(self, supported_formats=(), keyword_casing="auto"): self.reserved_words = set() for x in self.keywords: self.reserved_words.update(x.split()) - self.name_pattern = compile(r"^[_a-z][_a-z0-9\$]*$") + self.name_pattern = compile(r"^[_a-zA-Z][_a-zA-Z0-9\$]*$") self.special_commands = [] self.table_formats = supported_formats diff --git a/tests/test_smart_completion_public_schema_only.py b/tests/test_smart_completion_public_schema_only.py index 6134ff3..dfbe354 100644 --- a/tests/test_smart_completion_public_schema_only.py +++ b/tests/test_smart_completion_public_schema_only.py @@ -40,6 +40,18 @@ def complete_event(): return Mock() +def test_escape_name(completer): + + for name, expected_name in [# Upper case name shouldn't be escaped + ("BAR", "BAR"), + # This name is escaped and should start with back tick + ("2025todos", "`2025todos`"), + # normal case + ("people", "people"), + # table name with _underscore should not be escaped + ("django_users", "django_users")]: + assert completer.escape_name(name) == expected_name + def test_empty_string_completion(completer, complete_event): text = "" position = 0 From e3c2b077321ba661964a73c227b6f5a0535ec5d7 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sun, 2 Mar 2025 15:16:28 +0000 Subject: [PATCH 2/2] Fix failing tests --- CHANGELOG.md | 1 + tests/test_smart_completion_public_schema_only.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3685c5d..c75374f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bug Fixes * Fix a bug where the `\llm` command on alternate invocations weren't detected correctly. (#211) +* Do not escape upper table or column name. [(#185)](https://github.com/dbcli/litecli/issues/185) ### Internal diff --git a/tests/test_smart_completion_public_schema_only.py b/tests/test_smart_completion_public_schema_only.py index dfbe354..45909a8 100644 --- a/tests/test_smart_completion_public_schema_only.py +++ b/tests/test_smart_completion_public_schema_only.py @@ -314,7 +314,7 @@ def test_auto_escaped_col_names(completer, complete_event): result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event)) assert result == [ Completion(text="*", start_position=0), - Completion(text="`ABC`", start_position=0), + Completion(text="ABC", start_position=0), Completion(text="`insert`", start_position=0), Completion(text="id", start_position=0), ] + list(map(Completion, completer.functions)) + [Completion(text="select", start_position=0)] + list( @@ -329,7 +329,7 @@ def test_un_escaped_table_names(completer, complete_event): assert result == list( [ Completion(text="*", start_position=0), - Completion(text="`ABC`", start_position=0), + Completion(text="ABC", start_position=0), Completion(text="`insert`", start_position=0), Completion(text="id", start_position=0), ]