Skip to content

Commit 768be79

Browse files
authored
Merge pull request #218 from dbcli/krace/issue-185-remove-backtick
Do not escape the upper case names
2 parents be3a2b8 + e3c2b07 commit 768be79

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bug Fixes
1010

1111
* Fix a bug where the `\llm` command on alternate invocations weren't detected correctly. (#211)
12+
* Do not escape upper table or column name. [(#185)](https://github.com/dbcli/litecli/issues/185)
1213

1314
### Internal
1415

litecli/sqlcompleter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def __init__(self, supported_formats=(), keyword_casing="auto"):
258258
self.reserved_words = set()
259259
for x in self.keywords:
260260
self.reserved_words.update(x.split())
261-
self.name_pattern = compile(r"^[_a-z][_a-z0-9\$]*$")
261+
self.name_pattern = compile(r"^[_a-zA-Z][_a-zA-Z0-9\$]*$")
262262

263263
self.special_commands = []
264264
self.table_formats = supported_formats

tests/test_smart_completion_public_schema_only.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ def complete_event():
4040
return Mock()
4141

4242

43+
def test_escape_name(completer):
44+
45+
for name, expected_name in [# Upper case name shouldn't be escaped
46+
("BAR", "BAR"),
47+
# This name is escaped and should start with back tick
48+
("2025todos", "`2025todos`"),
49+
# normal case
50+
("people", "people"),
51+
# table name with _underscore should not be escaped
52+
("django_users", "django_users")]:
53+
assert completer.escape_name(name) == expected_name
54+
4355
def test_empty_string_completion(completer, complete_event):
4456
text = ""
4557
position = 0
@@ -302,7 +314,7 @@ def test_auto_escaped_col_names(completer, complete_event):
302314
result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
303315
assert result == [
304316
Completion(text="*", start_position=0),
305-
Completion(text="`ABC`", start_position=0),
317+
Completion(text="ABC", start_position=0),
306318
Completion(text="`insert`", start_position=0),
307319
Completion(text="id", start_position=0),
308320
] + list(map(Completion, completer.functions)) + [Completion(text="select", start_position=0)] + list(
@@ -317,7 +329,7 @@ def test_un_escaped_table_names(completer, complete_event):
317329
assert result == list(
318330
[
319331
Completion(text="*", start_position=0),
320-
Completion(text="`ABC`", start_position=0),
332+
Completion(text="ABC", start_position=0),
321333
Completion(text="`insert`", start_position=0),
322334
Completion(text="id", start_position=0),
323335
]

0 commit comments

Comments
 (0)