def match(self, table, whereClause=None, orderBy=None, **simple): assert not (whereClause and simple), \ "where/simple queries are mutually exclusive" if simple: whereClause = reduce(operator.and_, [where(k)==simple[k] for k in simple]) return self._match(table, whereClause, orderBy)
def check_querybuilder_matches(self): self.check_store_insertExtra() match = self.s.match("test_person", where("ID") == 5) assert match[0]['name'] == 'jack' match = self.s.match("test_person", ((where("name") == "fred") | (where("name") == "bob")), "name") self.assertEquals([u['name'] for u in match], ['bob', 'fred']) match = self.s.match("test_person", ((where("ID") > 1) & (where("ID") <= 4)) | (where("name").endswith('ck')), 'name desc') self.assertEquals([u['name'] for u in match], ['wanda', 'rick', 'jack', 'bob'])
def check_querybuilder_matches(self): self.check_store_insertExtra() match = self.s.match("test_person", where("ID")==5 ) assert match[0]['name'] == 'jack' match = self.s.match("test_person", ( ( where("name")=="fred" ) | ( where("name")=="bob" ) ), "name") self.assertEquals([u['name'] for u in match], ['bob','fred']) match = self.s.match("test_person", ((where("ID") > 1) &(where("ID") <= 4)) |(where("name").endswith('ck')), 'name desc') self.assertEquals( [u['name'] for u in match], ['wanda', 'rick', 'jack', 'bob'] )
def fetch(self, table, ID): res = self.match(table, where("ID") == ID) if len(res)!=1: raise LookupError, "match(%r, ID=%r) returned %i rows." \ % (table, ID, len(res)) return res[0]
def test_simple(self): clause = where('a') < 5 assert str(clause) == "(a < '5')", clause
def test_like(self): clause = where("name").startswith("a") self.assertEquals(str(clause), "(name LIKE 'a%')")
def test_complex(self): a = where("a") == 1 b = where("b") == 2 #import pdb; pdb.set_trace() clause = a | b self.assertEquals(str(clause), "((a = '1') OR (b = '2'))")
def check_oldmatch(self): self.check_store_insertExtra() match = self.s.match("test_person", where("ID") == 2) assert match[0]["name"] == "wanda", "new style broke" match = self.s.match("test_person", ID=2) assert match[0]["name"] == "wanda", "old style broke"
def check_match(self): assert self.wholedb() == [] self.populate() results = self.s.match("test_person", where("ID") == 1) assert results == [{"ID": 1, "name": "fred"}], str(results)
sendmail(header + msg + stmt) if __name__=="__main__": CLERK = duckbill.config.makeClerk() today = Date("today") lastDue = today - daysInLastMonth() + 15 nextDue = today + 15 dueAccounts = [] for acc in CLERK.match(duckbill.Account, where("status") != "closed"): #@TODO: can I do multiple where clauses? if acc.status=="comped": continue ## @TODO: call postCharges() but figure out how to trap errors [??] for sub in acc.subscriptions: try: sub.catchup() CLERK.store(acc) # not sub, because of bug... except Exception, e: print "ERROR [%s>%s]:" % (acc.account, sub.username), str(e) if acc.isDue(): dueAccounts.append(acc)
def check_match(self): assert self.wholedb() == [] self.populate() results = self.s.match("test_person", where("ID") == 1) assert results == [{"ID":1, "name":"fred"}], str(results)
def check_oldmatch(self): self.check_store_insertExtra() match = self.s.match("test_person", where("ID")==2) assert match[0]["name"] == "wanda", "new style broke" match = self.s.match("test_person", ID=2) assert match[0]["name"] == "wanda", "old style broke"
def fetch(self, table, ID): res = self.match(table, where("ID") == ID) if len(res) != 1: raise LookupError, "match(%r, ID=%r) returned %i rows." \ % (table, ID, len(res)) return res[0]