def as_sql(self): """ @return: bytes """ r = [] for q in self.children: if isinstance(q, Q): r.append(q.as_sql()) else: k, v = q sv = k.rsplit("__", 1) if len(sv) == 1: ops = "exact" else: ops = sv[1] lh = sv[0].encode() op = self.operators[ops] if ops == "in": vs = [ process_param(ve) for ve in v ] rh = b", ".join( vs ) rh = b'(' + rh + b')' else: rh = process_param(v) r.append(lh + op + rh) c = " %s " % self.connector c = c.encode() result = c.join(r) if self.negated: neg = b"NOT" else: neg = b"" return neg + b" ( " + result + b" )"
def to_db(self, value): """ 把python类型的数据转換为数据库的数据 """ r = {} for k, v in self.datatypedict.items(): if k in value: r[k] = v.to_db(value[k]) else: r[k] = process_param(v.to_db(v.default_value())) return r
def to_db(self, value): """ 把python类型的数据转換为数据库的数据 """ return process_param(bytes(value))
def __call__(self, lh, rh): f = process_param(rh[0]) s = process_param(rh[1]) return b" ".join((lh, b"BETWEEN", f, b"AND", s))
def __call__(self, lh, rh): vs = [ process_param(ve) for ve in rh ] rhV = b'(' + b", ".join( vs ) + b')' return b" ".join((lh, self.OPT, rhV))
def __call__(self, lh, rh): if rh is None: return b" ".join((lh, "IS NULL")) return b" ".join((lh, self.OPT, process_param(rh)))
def __call__(self, lh, rh): return b" ".join((lh, self.OPT, process_param(rh)))
def resolve_expression(self, metaClass): return process_param(self.value).decode()