Is there a pretty way to execute an SQL statement with a LIKE
in SQLObject?
This one works, but it's somewhat ugly:
fields = Foo.select("field LIKE '%%%s%%'" % bar)
In sqlobject.sqlbuilder
there is an undocumented class called LIKE
which can be used amongst other query elements.
For example:
from sqlobject.sqlbuilder import LIKE
class Customer(SQLObject):
name = StringCol()
...
# this search is case-dependent
rows = Customer.select(LIKE(Customer.q.name, "%Smith%"))
class ILIKE(LIKE):
op = 'ILIKE'
# this search is case-independent, works on PostgreSQL, not sure about others
rows = Customer.select(ILIKE(Customer.q.name, '%smith%'))
SqlBuilder has a LIKE
function (and also startswith
and endswith
ones that build appropriate LIKE
clauses).