Executing SQL LIKE in SQLObject

Go To StackoverFlow.com

0

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)
2009-06-16 19:26
by Alex


1

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%'))
2014-11-16 23:51
by David McNab


0

SqlBuilder has a LIKE function (and also startswith and endswith ones that build appropriate LIKE clauses).

2009-06-16 20:01
by Alex Martelli
Ads