def __ne__(self, other): if isinstance(other, Column): return SQL_Param("%s != %s" % (self.full_name, other.full_name)) else: if other == None: # if Column != None, means column_name NOT Null return SQL_Param("%s NOT NULL" % self.full_name) else: return SQL_Param("%s != %s" % (self.full_name, self.to_sql_param(other)))
def __truediv__(self, other): """Column / other, for python2,3 compatible. """ if isinstance(other, Column): return SQL_Param( param="%s / %s" % (self.full_name, other.full_name), dtype=self.data_type, ) else: return SQL_Param( param="%s / %s" % (self.full_name, self.to_sql_param(other)), dtype=self.data_type, )
def __mul__(self, other): """Column * other. """ if isinstance(other, Column): return SQL_Param( param="%s * %s" % (self.full_name, other.full_name), dtype=self.data_type, ) else: return SQL_Param( param="%s * %s" % (self.full_name, self.to_sql_param(other)), dtype=self.data_type, )
def in_(self, choice): """WHERE ... IN ... clause. """ return SQL_Param(param="%s IN (%s)" % ( self.full_name, ", ".join([self.to_sql_param(i) for i in choice]), ), sql_name="IN")
def like(self, wildcards): """WHERE ... LIKE ... clause. """ return SQL_Param( param="%s LIKE %s" % (self.full_name, self.to_sql_param(wildcards)), sql_name="LIKE", )
def to_SQL_Param_instance(self): # 如果只是列的话, param使用column_name, 这样才能让Row能够直接通过列名 # 而不是全名来访问值。 return SQL_Param( param="%s" % self.column_name, column_name=self.column_name, full_name=self.full_name, table_name=self.table_name, dtype=self.data_type, )
def desc(self): """Construct an Sql parameter in ORDER BY clause or CREATE INDEX clause. """ return SQL_Param( param="%s DESC" % self.full_name, column_name=self.column_name, full_name=self.full_name, table_name=self.table_name, sql_name="DESC", )
def between(self, lowerbound, upperbound): """WHERE ... BETWEEN ... AND ... clause. """ if isinstance(lowerbound, Column) and isinstance(upperbound, Column): return SQL_Param( param="%s BETWEEN %s AND %s" % ( self.full_name, lowerbound.full_name, upperbound.full_name, ), sql_name="BETWEEN", ) elif isinstance(lowerbound, Column) \ and (not isinstance(upperbound, Column)): return SQL_Param( param="%s BETWEEN %s AND %s" % ( self.full_name, lowerbound.full_name, self.to_sql_param(upperbound), ), sql_name="BETWEEN", ) elif isinstance(upperbound, Column) \ and (not isinstance(lowerbound, Column)): return SQL_Param( param="%s BETWEEN %s AND %s" % ( self.full_name, self.to_sql_param(lowerbound), upperbound.full_name, ), sql_name="BETWEEN", ) else: return SQL_Param( param="%s BETWEEN %s AND %s" % ( self.full_name, self.to_sql_param(lowerbound), self.to_sql_param(upperbound), ), sql_name="BETWEEN", )
def abs(self, column): """ABS(column) function. """ if isinstance(column, Column): return SQL_Param( "ABS(%s)" % column.column_name, column_name=column.column_name, table_name=column.table_name, func_name="_abs_", dtype=column.data_type, ) else: raise Exception("func.abs()'s argument has to be Column object.")
def count(self, column): """COUNT(column) function. """ if isinstance(column, Column): return SQL_Param( "COUNT(%s)" % column.column_name, column_name=column.column_name, table_name=column.table_name, func_name="_count_", dtype=dtype.INTEGER, ) else: raise Exception("func.count()'s argument has to be Column object.")
def round(self, column): """ROUND(column) function. """ if isinstance(column, Column): return SQL_Param( "ROUND(%s)" % column.column_name, column_name=column.column_name, table_name=column.table_name, func_name="_round_", dtype=dtype.TEXT, ) else: raise Exception("func.upper()'s argument has to be Column object.")
def lower(self, column): """LOWER(column) function. """ if isinstance(column, Column): return SQL_Param( "LOWER(%s)" % column.column_name, column_name=column.column_name, table_name=column.table_name, func_name="_lower_", dtype=dtype.TEXT, ) else: raise Exception("func.lower()'s argument has to be Column object.")
def length(self, column): """LENGTH(column) function. """ if isinstance(column, Column): return SQL_Param( "LENGTH(%s)" % column.column_name, column_name=column.column_name, table_name=column.table_name, func_name="_length_", dtype=dtype.INTEGER, ) else: raise Exception( "func.length()'s argument has to be Column object.")
def __neg__(self): """- Column. """ return SQL_Param(param="- %s" % self.full_name, dtype=self.data_type)
def __pos__(self): """+ Column. """ return SQL_Param(param="+ %s" % self.full_name, dtype=self.data_type)
def __ge__(self, other): if isinstance(other, Column): return SQL_Param("%s >= %s" % (self.full_name, other.full_name)) else: return SQL_Param("%s >= %s" % (self.full_name, self.to_sql_param(other)))