Skip to content

Commit

Permalink
Fix alias insertion
Browse files Browse the repository at this point in the history
SQLite LIKE operator is case-insensitive. Hence the replacement must be case-insensitive too. If it is not, the keyword found by LIKE might not be replaced and will be found again and again. That will cause unlimited growth of sql_results.

Example:
https://en.cppreference.com/w/cpp/memory/allocator
and Allocator  template argument

Another option would be using GLOB instead of LIKE for case-sensitive search. Whether it is better or not and search pattern selection is out of scope of this commit.
  • Loading branch information
glenvt18 authored Jan 14, 2025
1 parent ff8a77e commit 8ec9324
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cppman/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def rebuild_index(self):
% (table, k, k, k, k, k, k)).fetchall()

for id, keyword in sql_results:
keyword = keyword.replace("%s" % k, "%s" % a)
keyword = re.sub(re.escape("%s" % k), "%s" % a, keyword, flags=re.IGNORECASE)

self.db_cursor.execute(
'INSERT INTO "%s_keywords" (id, keyword) '
Expand Down

0 comments on commit 8ec9324

Please sign in to comment.