MCPcopy Index your code
hub / github.com/clips/pattern / SQL

Method SQL

pattern/db/__init__.py:1112–1136  ·  view source on GitHub ↗

For example, filter for small pets with tails or wings (which is not the same as small pets with tails or pets with wings): >>> Group( >>> filter("type", "pet"), >>> filter("weight", (4,6), ":"), >>> Group( >>>

(self, **kwargs)

Source from the content-addressed store, hash-verified

1110 self.operator = kwargs.get("operator", AND)
1111
1112 def SQL(self, **kwargs):
1113 """ For example, filter for small pets with tails or wings
1114 (which is not the same as small pets with tails or pets with wings):
1115 >>> Group(
1116 >>> filter("type", "pet"),
1117 >>> filter("weight", (4,6), ":"),
1118 >>> Group(
1119 >>> filter("tail", True),
1120 >>> filter("wing", True), operator=OR))
1121 Yields:
1122 "type='pet' and weight between 4 and 6 and (tail=1 or wing=1)"
1123 """
1124 # Remember to pass the right escape() function as optional parameter.
1125 a = []
1126 for filter in self:
1127 # Traverse subgroups recursively.
1128 if isinstance(filter, Group):
1129 a.append("(%s)" % filter.SQL(**kwargs))
1130 continue
1131 # Convert filter() to string with cmp() - see above.
1132 if isinstance(filter, (list, tuple)):
1133 a.append(cmp(*filter, **kwargs))
1134 continue
1135 raise TypeError, "Group can contain other Group or filter(), not %s" % type(filter)
1136 return (" %s " % self.operator).join(a)
1137
1138 sql = SQL
1139

Callers 6

test_groupMethod · 0.95
_escapeFunction · 0.45
updateMethod · 0.45
deleteMethod · 0.45
SQLMethod · 0.45
test_queryMethod · 0.45

Calls 2

cmpFunction · 0.85
appendMethod · 0.45

Tested by 2

test_groupMethod · 0.76
test_queryMethod · 0.36