def genIndex(self, node): new_exp = None if self.column_name == "*": new_exp = copy.deepcopy(self) return new_exp if self.table_name != "": if self.table_name not in node.table_alias_dic.keys(): if self.table_name not in node.table_list: # TODO error pass tmp_table = util.searchTable(self.table_name) if tmp_table is None: return None index = tmp_table.getColumnIndexByName(self.column_name) new_exp = Column(self.table_name, index) new_exp.column_name = int(new_exp.column_name) new_exp.column_type = self.column_type else: tmp_column = util.searchColumn(self.column_name) tmp_table = None for tmp in tmp_column: if tmp.table_schema.table_name in node.table_list or tmp.table_schema.table_name in node.table_alias_dic.values(): tmp_table = searchTable(tmp.table_schema.table) break if tmp_table is None: return None index = tmp_table.getColumnIndexByName(self.column_name) new_exp = Column(tmp.table_schema.table_name, index) new_exp.column_name = int(new_exp.column_name) new_exp.column_name = self.column_type return new_exp
def genTableName(self, node): if self.table_name != "": table = util.searchTable(self.table_name) if table is None and self.table_name in node.table_alias_dic.keys(): table = util.searchTable(node.table_alias_dic[self.table_name]) if table is None: # TODO error return print table.table_name, self.column_name self.column_type = table.getColumnByName(self.column_name).column_type return if self.column_name == "*": return col_list = util.searchColumn(self.column_name) for col in col_list: if col.table_schema.table_name in node.table_list: self.table_name = col.table_schema.table_name self.column_type = col.table_schema.getColumnByName(self.column_name).column_type return for key in node.table_alias_dic.keys(): if col.table_schema.table_name == self.table_alias_dic[key]: self.table_name = key self.column_type = col.table_schema.getColumnByName(self.column_name).column_type return