Пример #1
0
	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" )"
Пример #2
0
    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
Пример #3
0
    def to_db(self, value):
        """
		把python类型的数据转換为数据库的数据
		"""
        return process_param(bytes(value))
Пример #4
0
	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))
Пример #5
0
	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))
Пример #6
0
	def __call__(self, lh, rh):
		if rh is None:
			return b" ".join((lh, "IS NULL"))
		return b" ".join((lh, self.OPT, process_param(rh)))
Пример #7
0
	def __call__(self, lh, rh):
		return b" ".join((lh, self.OPT, process_param(rh)))
Пример #8
0
 def resolve_expression(self, metaClass):
     return process_param(self.value).decode()