Coverage for src/local_deep_research/utilities/sql_utils.py: 100%

2 statements  

« prev     ^ index     » next       coverage.py v7.15.1, created at 2026-07-19 23:35 +0000

1"""SQL helper utilities with no framework or DB-session dependencies. 

2 

3Deliberately dependency-free (no flask, no encrypted_db imports) so that 

4lightweight, standalone modules — such as the read-only ``journal_quality`` 

5reference DB — can escape LIKE wildcards without transitively pulling in 

6the web stack. 

7""" 

8 

9 

10def escape_like(value: str) -> str: 

11 """Escape SQL LIKE metacharacters to prevent wildcard injection. 

12 

13 Escapes the backslash first, then ``%`` and ``_``. Pair with 

14 ``escape="\\\\"`` on the ``.like()`` / ``.ilike()`` call so the database 

15 treats the backslash as the escape character. 

16 """ 

17 return value.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")