def find_sclass(s, sql): stack = [s] while len(stack): tmp_stack = [] while len(stack): root = stack.pop() if type(root) == SClass: return root # 如果是filter,就在where中加入filter if root.param_1.value == 'Filter': sql.padding_where(root.param_1.param_1, root.param_1.param_2) if not is_contained(root.param_1.t_name, root.param_2.t_name): sql.padding_join( find_join_t(root.param_1.T, root.key1, root.key2), root.key1, root.key2) tmp_stack.append(root.param_2) if root.param_2.value == 'Filter': sql.padding_where(root.param_2.param_1, root.param_2.param_2) if not is_contained(root.param_1.t_name, root.param_2.t_name): sql.padding_join( find_join_t(root.param_2.T, root.key1, root.key2), root.key1, root.key2) tmp_stack.append(root.param_1) stack = tmp_stack
def generate_ac_sql(c, sql): #这个只判断c 只填join 和 where # 如果两个参数不同表, join 和 on 操作 if type(c) == cClass: return sql stack = [c] while len(stack): tmp_stack = [] while len(stack): root = stack.pop() if not is_contained(root.param_1.t_name, root.param_2.t_name): if root.param_1.value != 'c' and root.param_1.c_type != 'string': sql.padding_join( find_join_t(root.param_1.T, root.key1, root.key2), root.key1, root.key2) # 如果是filter,就在where中加入filter if root.param_1.value == 'Filter': sql.padding_where(root.param_1.param_1, root.param_1.param_2) if root.param_2.value == 'Filter': sql.padding_where(root.param_2.param_1, root.param_2.param_2) if type(root.param_1) != cClass and type(root.param_1) != In: tmp_stack.append(root.param_1) if type(root.param_2) != cClass and type(root.param_2) != In: tmp_stack.append(root.param_2) stack = tmp_stack return sql
def generate_cc_sql(s, sql): #如果两个参数不同表, join 和 on 操作 stack = [s] while len(stack): tmp_stack = [] while len(stack): root = stack.pop() if not is_contained(root.param_1.t_name, root.param_2.t_name): if root.param_1.value == 'T': sql.padding_join(root.param_1, root.key1, root.key2) elif root.param_1.value != 'c' and root.param_1.c_type != 'string': sql.padding_join( find_join_t(root.param_1.T, root.key1, root.key2), root.key1, root.key2) elif root.param_2.value != 'c' and root.param_2.type != 'string': sql.padding_join( find_join_t(root.param_2.T, root.key1, root.key2), root.key1, root.key2) #如果是filter,就在where中加入filter if root.param_1.value == 'Filter': sql.padding_where(root.param_1.param_1, root.param_1.param_2) elif root.param_2.value == 'Filter': sql.padding_where(root.param_2.param_1, root.param_2.param_2) #如果是c_str 就在select中加入c if type(root.param_1) == cClass: if root.param_1.c_type == 'string': sql.padding_select(root.param_1) sql.padding_from(root.param_1.T) #不是cstring 就是cnumber else: sql.padding_orderby(root.param_1) if type(root.param_2) == cClass: if root.param_2.c_type == 'string': sql.padding_select(root.param_2) sql.padding_from(root.param_2.T) else: sql.padding_orderby(root.param_2) if type(root.param_1) != In and type(root.param_1) != cClass: tmp_stack.append(root.param_1) if type(root.param_2) != In and type(root.param_2) != cClass: tmp_stack.append(root.param_2) stack = tmp_stack return sql
def a_generate_sql(c, sql): # 这个c是modify的c, 遇到cClass放到select中,Filter放到where中 # 如果两个参数不同表, join 和 on 操作 if type(c) == Count: sql.padding_select(c) return sql stack = [c] while len(stack): tmp_stack = [] while len(stack): root = stack.pop() if is_contained(root.param_1.t_name, root.param_2.t_name): # join filter.T if root.param_1.value == 'Filter': sql.padding_join( find_join_t(root.param_1.T, root.key1, root.key2), root.key1, root.key2) else: sql.padding_join( find_join_t(root.param_2.T, root.key1, root.key2), root.key1, root.key2) if root.param_1.value == 'Filter': sql.padding_where(root.param_1.param_1, root.param_1.param_2) if root.param_2.value == 'Filter': sql.padding_where(root.param_2.param_1, root.param_2.param_2) if type(root.param_1) == Count: # 放到select中 sql.padding_select(root.param_1) if type(root.param_2) == Count: sql.padding_select(root.param_2) if root.param_1 and type(root.param_1) != In and type( root.param_1) != Count: tmp_stack.append(root.param_1) if root.param_2 and type(root.param_2) != In and type( root.param_2) != Count: tmp_stack.append(root.param_2) stack = tmp_stack return sql