本文整理汇总了Python中django.db.models.sql.where.WhereNode类的典型用法代码示例。如果您正苦于以下问题:Python WhereNode类的具体用法?Python WhereNode怎么用?Python WhereNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WhereNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_or
def test_or(self):
where = WhereNode()
where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND)
where.add((Constraint("givenName", "givenName", CharField()), 'exact',
"bar"), OR)
self.assertEquals(where_as_ldap(where), ("(|(cn=foo)(givenName=bar))",
[]))
示例2: as_sql
def as_sql(self, compiler, connection):
if isinstance(self.lhs, MultiColSource):
# For multicolumn lookups we need to build a multicolumn where clause.
# This clause is either a SubqueryConstraint (for values that need to be compiled to
# SQL) or a OR-combined list of (col1 = val1 AND col2 = val2 AND ...) clauses.
from django.db.models.sql.where import WhereNode, SubqueryConstraint, AND, OR
root_constraint = WhereNode(connector=OR)
if self.rhs_is_direct_value():
values = [get_normalized_value(value, self.lhs) for value in self.rhs]
for value in values:
value_constraint = WhereNode()
for source, target, val in zip(self.lhs.sources, self.lhs.targets, value):
lookup_class = target.get_lookup('exact')
lookup = lookup_class(target.get_col(self.lhs.alias, source), val)
value_constraint.add(lookup, AND)
root_constraint.add(value_constraint, OR)
else:
root_constraint.add(
SubqueryConstraint(
self.lhs.alias, [target.column for target in self.lhs.targets],
[source.name for source in self.lhs.sources], self.rhs),
AND)
return root_constraint.as_sql(compiler, connection)
else:
return super(RelatedIn, self).as_sql(compiler, connection)
示例3: as_sql
def as_sql(self, compiler, connection):
if isinstance(self.lhs, MultiColSource):
assert self.rhs_is_direct_value()
self.rhs = get_normalized_value(self.rhs, self.lhs)
from django.db.models.sql.where import WhereNode, AND
root_constraint = WhereNode()
for target, source, val in zip(self.lhs.targets, self.lhs.sources, self.rhs):
lookup_class = target.get_lookup(self.lookup_name)
root_constraint.add(
lookup_class(target.get_col(self.lhs.alias, source), val), AND)
return root_constraint.as_sql(compiler, connection)
return super().as_sql(compiler, connection)
示例4: test_float_field
def test_float_field(self):
where = WhereNode()
where.add((Constraint("uid", "uid", FloatField()), 'exact', 1.2), AND)
self.assertEquals(where_as_ldap(where), ("(uid=1.2)", []))
where = WhereNode()
where.add((Constraint("uid", "uid", FloatField()), 'gte', 1.2), AND)
self.assertEquals(where_as_ldap(where), ("(uid>=1.2)", []))
where = WhereNode()
where.add((Constraint("uid", "uid", FloatField()), 'lte', 1.2), AND)
self.assertEquals(where_as_ldap(where), ("(uid<=1.2)", []))
示例5: test_integer_field
def test_integer_field(self):
where = WhereNode()
where.add(self._build_lookup("uid", 'exact', 1, field=IntegerField), AND)
self.assertEqual(where_as_ldap(where), "(uid=1)")
where = WhereNode()
where.add(self._build_lookup("uid", 'gte', 1, field=IntegerField), AND)
self.assertEqual(where_as_ldap(where), "(uid>=1)")
where = WhereNode()
where.add(self._build_lookup("uid", 'lte', 1, field=IntegerField), AND)
self.assertEqual(where_as_ldap(where), "(uid<=1)")
示例6: test_integer_field
def test_integer_field(self):
where = WhereNode()
where.add((Constraint("uid", "uid", IntegerField()), 'exact', 1), AND)
self.assertEquals(where_as_ldap(where), ("(uid=1)", []))
where = WhereNode()
where.add((Constraint("uid", "uid", IntegerField()), 'gte', 1), AND)
self.assertEquals(where_as_ldap(where), ("(uid>=1)", []))
where = WhereNode()
where.add((Constraint("uid", "uid", IntegerField()), 'lte', 1), AND)
self.assertEquals(where_as_ldap(where), ("(uid<=1)", []))
示例7: test_float_field
def test_float_field(self):
where = WhereNode()
where.add(self._build_lookup("uid", 'exact', 1.2, field=FloatField), AND)
self.assertEqual(where_as_ldap(where), "(uid=1.2)")
where = WhereNode()
where.add(self._build_lookup("uid", 'gte', 1.2, field=FloatField), AND)
self.assertEqual(where_as_ldap(where), "(uid>=1.2)")
where = WhereNode()
where.add(self._build_lookup("uid", 'lte', 1.2, field=FloatField), AND)
self.assertEqual(where_as_ldap(where), "(uid<=1.2)")
示例8: test_datetime_field
def test_datetime_field(self):
dt = datetime.datetime(2018, 6, 25, 20, 21, 22, tzinfo=UTC)
where = WhereNode()
where.add(self._build_lookup("modifyTimestamp", 'exact', dt, field=fields.DateTimeField,), AND)
self.assertEqual(self._where_as_ldap(where), "(modifyTimestamp=20180625202122.000000Z)")
where = WhereNode()
where.add(self._build_lookup("modifyTimestamp", 'lte', dt, field=fields.DateTimeField,), AND)
self.assertEqual(self._where_as_ldap(where), "(modifyTimestamp<=20180625202122.000000Z)")
where = WhereNode()
where.add(self._build_lookup("modifyTimestamp", 'gte', dt, field=fields.DateTimeField,), AND)
self.assertEqual(self._where_as_ldap(where), "(modifyTimestamp>=20180625202122.000000Z)")
示例9: test_char_field_contains
def test_char_field_contains(self):
where = WhereNode()
where.add(self._build_lookup("cn", 'contains', "test"), AND)
self.assertEqual(where_as_ldap(where), "(cn=*test*)")
where = WhereNode()
where.add(self._build_lookup("cn", 'contains', "te*st"), AND)
self.assertEqual(where_as_ldap(where), "(cn=*te\\2ast*)")
示例10: test_char_field_in
def test_char_field_in(self):
where = WhereNode()
where.add(self._build_lookup("cn", 'in', ["foo", "bar"]), AND)
self.assertEqual(where_as_ldap(where), "(|(cn=foo)(cn=bar))")
where = WhereNode()
where.add(self._build_lookup("cn", 'in', ["(foo)", "(bar)"]), AND)
self.assertEqual(where_as_ldap(where), "(|(cn=\\28foo\\29)(cn=\\28bar\\29))")
示例11: test_char_field_endswith
def test_char_field_endswith(self):
where = WhereNode()
where.add(self._build_lookup("cn", 'endswith', "test"), AND)
self.assertEqual(where_as_ldap(where), "(cn=*test)")
where = WhereNode()
where.add(self._build_lookup("cn", 'endswith', "te*st"), AND)
self.assertEqual(where_as_ldap(where), "(cn=*te\\2ast)")
示例12: test_list_field_contains
def test_list_field_contains(self):
where = WhereNode()
where.add(self._build_lookup("memberUid", 'contains', 'foouser', field=ListField), AND)
self.assertEqual(where_as_ldap(where), "(memberUid=foouser)")
where = WhereNode()
where.add(self._build_lookup("memberUid", 'contains', '(foouser)', field=ListField), AND)
self.assertEqual(where_as_ldap(where), "(memberUid=\\28foouser\\29)")
示例13: test_char_field_exact
def test_char_field_exact(self):
where = WhereNode()
where.add(self._build_lookup('cn', 'exact', "test"), AND)
self.assertEqual(where_as_ldap(where), "(cn=test)")
where = WhereNode()
where.add(self._build_lookup('cn', 'exact', "(test)"), AND)
self.assertEqual(where_as_ldap(where), "(cn=\\28test\\29)")
示例14: test_list_field_startswith
def test_list_field_startswith(self):
where = WhereNode()
where.add((Constraint("cn", "cn", ListField()), 'startswith', "test"), AND)
self.assertEquals(where_as_ldap(where), ("(cn=test*)", []))
where = WhereNode()
where.add((Constraint("cn", "cn", ListField()), 'startswith', "te*st"), AND)
self.assertEquals(where_as_ldap(where), ("(cn=te\\2ast*)", []))
示例15: test_list_field_contains
def test_list_field_contains(self):
where = WhereNode()
where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', 'foouser'), AND)
self.assertEquals(where_as_ldap(where), ("(memberUid=foouser)", []))
where = WhereNode()
where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', '(foouser)'), AND)
self.assertEquals(where_as_ldap(where), ("(memberUid=\\28foouser\\29)", []))