def execute_alert(node): if not __check_power(node.type, [node.table_name]): return if not data_dict.has_table(node.table_name): print "Error: The table does not exist." return names = data_dict.table_attr_names(node.table_name) table = TableFile(data_dict, node.table_name) data = table.load_data() if node.op == "ADD": if node.attr_list.attr_name in names: print "Error: The attr's name already exists." return data_dict.dict[node.table_name] += [node.attr_list] for idx in range(len(data)): data[idx].append("NULL") elif node.op == "DROP": attr_name = node.attr_list[0] if attr_name not in names: print "Error: The attr's name does not exist." return old_list = data_dict.dict[node.table_name] data_dict.dict[node.table_name] = [attr for attr in old_list if attr.attr_name != attr_name] idx_remove = names.index(attr_name) for idx in range(len(data)): del data[idx][idx_remove] index_dict.drop_index(node.table_name, attr_name) table.data_list = data table.write_back() data_dict.write_back() print "Alert table successful."
def execute_delete(node): if not __check_power(node.type, [node.table_name]): return if not __check_table([node.table_name]): print("Error: This table isn't exists.") return data_dict = DataDict(node.table_name) names = data_dict.table_attr_names() table = TableFile(data_dict, node.table_name) table_data = table.load_data() old_len = len(table_data) print("where_list: ", node.where_list, type(node.where_list)) # for where_item in node.where_list: # print("where_item", where_item) try: table.data_list = [] for line in table_data: is_true = check_where(node.where_list, names, line) print("is_true: ", is_true) if VISIBLE is True else None if not is_true: table.data_list.append(line) except Exception as ex: print("Error: %s." % ex) return new_len = len(table.data_list) table.write_back() index_dict.load_index() # 表中记录删除后,索引文件也要相应的发生改变 print("%d line(s) are deleted." % (old_len - new_len))
def execute_alert(node): if not __check_power(node.type, [node.table_name]): return if not data_dict.has_table(node.table_name): print "Error: The table does not exist." return names = data_dict.table_attr_names(node.table_name) table = TableFile(data_dict, node.table_name) data = table.load_data() if node.op == "ADD": if node.attr_list.attr_name in names: print "Error: The attr's name already exists." return data_dict.dict[node.table_name] += [node.attr_list] for idx in range(len(data)): data[idx].append("NULL") elif node.op == "DROP": attr_name = node.attr_list[0] if attr_name not in names: print "Error: The attr's name does not exist." return old_list = data_dict.dict[node.table_name] data_dict.dict[node.table_name] = [ attr for attr in old_list if attr.attr_name != attr_name ] idx_remove = names.index(attr_name) for idx in range(len(data)): del data[idx][idx_remove] index_dict.drop_index(node.table_name, attr_name) table.data_list = data table.write_back() data_dict.write_back() print "Alert table successful."
def execute_delete(node): if not __check_power(node.type, [node.table_name]): return if not data_dict.has_table(node.table_name): print "Error: The table does not exist." return names = data_dict.table_attr_names(node.table_name) table = TableFile(data_dict, node.table_name) data = table.load_data() old_len = len(data) try: table.data_list = [line for line in data if not check_where(node.where_list, names, line)] except Exception, e: print "Error: %s." % e # print traceback.format_exc() return
def execute_delete(node): if not __check_power(node.type, [node.table_name]): return if not data_dict.has_table(node.table_name): print "Error: The table does not exist." return names = data_dict.table_attr_names(node.table_name) table = TableFile(data_dict, node.table_name) data = table.load_data() old_len = len(data) try: table.data_list = [ line for line in data if not check_where(node.where_list, names, line) ] except Exception, e: print "Error: %s." % e # print traceback.format_exc() return
def execute_delete(node): if not __check_power(node.type, [node.table_name]): return if not data_dict.has_table(node.table_name): print("Error: The table does not exist.") return names = data_dict.table_attr_names(node.table_name) table = TableFile(data_dict, node.table_name) data = table.load_data() old_len = len(data) try: table.data_list = [line for line in data if not check_where(node.where_list, names, line)] except Exception as e: print("Error: %s." % e) # print traceback.format_exc() return new_len = len(table.data_list) table.write_back() index_dict.load_index() print("%d line(s) are deleted." % (old_len - new_len))