Skip to content

Commit

Permalink
Fix issue with ORDER BY case sensitivity, closes #405
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmezzetti committed Jan 9, 2023
1 parent d926dbc commit d92a076
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/python/txtai/database/sql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def tokenize(self, query):
# Get position of clause keywords. For multi-term clauses, validate next token matches as well
for x, token in enumerate(tokens):
t = token.lower()
if t not in positions and t in SQL.CLAUSES and (t not in ["group", "order"] or (x + 1 < len(tokens) and tokens[x + 1] == "by")):
if t not in positions and t in SQL.CLAUSES and (t not in ["group", "order"] or (x + 1 < len(tokens) and tokens[x + 1].lower() == "by")):
positions[t] = x

return (tokens, positions)
Expand Down
8 changes: 8 additions & 0 deletions test/python/testdatabase/testsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ def testSimilar(self):
self.assertSql("where", prefix + "where coalesce(similar('abc'), similar('abc'))", "coalesce(__SIMILAR__0, __SIMILAR__1)")
self.assertSql("similar", prefix + "where coalesce(similar('abc'), similar('abc'))", [["abc"], ["abc"]])

def testUpper(self):
"""
Tests SQL statements are case insensitive.
"""

self.assertSql("groupby", "SELECT * FROM TXTAI WHERE a = 1 GROUP BY id", "s.id")
self.assertSql("orderby", "SELECT * FROM TXTAI WHERE a = 1 ORDER BY id", "s.id")

def testWhereBasic(self):
"""
Test basic where clauses
Expand Down

0 comments on commit d92a076

Please sign in to comment.