Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion litecli/sqlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions tests/test_smart_completion_public_schema_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -302,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),
Copy link
Contributor Author

@kracekumar kracekumar Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous tests were escaping the upper case column name and not sure why though. If there is a solid case, we can close this PR. I don't see any issue of passing upper case as is to sqlite3.

sqlite> .open :memory;
sqlite> create table TEST(ID int);
sqlite> insert into TEST(1);
Parse error: near "1": syntax error
  insert into TEST(1);
                   ^--- error here
sqlite> insert into TEST values(1);
sqlite> select ID from TEST;
1
sqlite>

Completion(text="`insert`", start_position=0),
Completion(text="id", start_position=0),
] + list(map(Completion, completer.functions)) + [Completion(text="select", start_position=0)] + list(
Expand All @@ -317,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),
]
Expand Down
Loading