[Sqlalchemy-tickets] Issue #4254: No way to combine case-insensitive contains() with autoescape (zz
Brought to you by:
zzzeek
From: vr2262 <iss...@bi...> - 2018-05-16 00:26:15
|
New issue 4254: No way to combine case-insensitive contains() with autoescape https://bitbucket.org/zzzeek/sqlalchemy/issues/4254/no-way-to-combine-case-insensitive vr2262: I would like to filter a query with `ILIKE` while escaping special characters like `%` and `_`. I tried this: ``` #!python from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker Base = declarative_base() class Example(Base): __tablename__ = 'example' id = Column(Integer, primary_key=True) string_col = Column(String) session = sessionmaker()() session.add(Example(string_col='S%mething')) search_string = 's%' print( session.query(Example) .filter( func.lower(Example.string_col) .contains(func.lower(search_string), autoescape=True) ) ) ``` But I get the error `TypeError: String value expected when autoescape=True` because `contains()` expects an actual string as the first argument. Ideally SQLAlchemy would provide this feature out of the box, perhaps with `icontains()` or `contains(insensitive=True, ...)`. |