0

有没有一种很好的方法来执行带有LIKEin SQLObject 的 SQL 语句?

这个可行,但有点难看:

    fields = Foo.select("field LIKE '%%%s%%'" % bar)
4

2 回答 2

1

其中sqlobject.sqlbuilder有一个未记录的类LIKE,可以在其他查​​询元素中使用。

例如:

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-16T23:51:23.517 回答
0

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

于 2009-06-16T20:01:23.527 回答