Exemplo n.º 1
0
    def process(self, instrucction):
        # Obteniendo tabla de la cual voy a borrar
        database_id = SymbolTable().useDatabase
        table_tp = TypeChecker().searchTable(database_id, self.table)
        table_cont = DataController().extractTable(self.table, self.line, self.column)
        headers = TypeChecker().searchColumnHeadings(table_tp)
        table_delete = pd.DataFrame(table_cont)

        if self.params == None:

            pk_col_name = TypeChecker().searchColPrimaryKey(table_tp)
            if pk_col_name == []:  # NO HAY LLAVE PRIMARIA
                pk_list = table_delete.index.tolist()
                print(pk_list)
                for pk in pk_list:
                    DataController().delete(self.table, pk, self.line, self.column)

            else:
                table_delete.columns = headers
                list_pks = []
                for col in pk_col_name:
                    list_pks.append(col.name)

                pk_list = table_delete[list_pks].values.tolist()
                print(pk_list)
                for pk in pk_list:
                    DataController().delete(self.table, pk, self.line, self.column)

        else:
            for option in self.params:
                if isinstance(option, Where):
                    table_delete.columns = headers
                    storage_columns(table_cont, headers,
                                    self.line, self.column)
                    storage_table(table_cont, headers, self.table,
                                  self.line, self.column)
                    table_result = option.process(
                        instrucction, table_delete, self.table)

                    pk_col_name = TypeChecker().searchColPrimaryKey(table_tp)
                    if pk_col_name == []:  # NO HAY LLAVE PRIMARIA
                        pk_list = table_result.index.to_list()
                        print(pk_list)
                        for pk in pk_list:
                            DataController().delete(self.table, pk, self.line, self.column)
                    else:
                        table_result.columns = headers
                        list_pks = []
                        for col in pk_col_name:
                            list_pks.append(col.name)

                        pk_list = table_result[list_pks].values.tolist()
                        print(pk_list)
                        for pk in pk_list:
                            DataController().delete(self.table, pk, self.line, self.column)

                    break
        return None
Exemplo n.º 2
0
    def process(self, instruction):
        # Obteniendo tabla de la cual voy a hacer el update
        database_id = SymbolTable().useDatabase
        table_tp = TypeChecker().searchTable(database_id, self.table)
        table_cont = DataController().extractTable(self.table, self.line, self.column)
        headers = TypeChecker().searchColumnHeadings(table_tp)
        table_update = pd.DataFrame(table_cont)

        tuplas = []  # t[0] = nombre columna, t[1] = valor a cambiar

        for column in self.arr_columns_vals:
            tuplas.append(column.process(instruction))
        d = {}
        d_col_names = {}
        # validando nombres de columnas ingresados
        for t in tuplas:
            if not t[0] in headers:
                desc = f'Nombre de columna invalido, {t[0]}'
                ErrorController().add(26, 'Execution', desc, self.line, self.column)
                return None
            else:
                d[headers.index(t[0])] = t[1].value
                d_col_names[t[0]] = t[1].value

        # validando tipo de valores para las columnas
        print(d_col_names)
        checker = CreateTB(None, None, None, None)
        for key in list(d_col_names.keys()):
            column = TypeChecker().searchColumn(table_tp, key).__dict__
            is_correct = checker.validateType(
                column['_dataType'], d_col_names.get(key), False)
            if not is_correct:
                desc = f'Valor no valido para la columna {key}'
                ErrorController().add(9, 'Execution', desc, self.line, self.column)
                return None
            if not realizeCheck(column, d_col_names, self.line, self.column):
                return None
        # CAMBIAR TODOS LOS REGISTROS DE LA TABLA
        if self.params == None:

            pk_col_name = TypeChecker().searchColPrimaryKey(table_tp)
            if pk_col_name == []:  # NO HAY LLAVE PRIMARIA

                pk_list = range(len(table_update.index))
                print(pk_list)
                for pk in pk_list:
                    DataController().update(self.table, d, [
                        pk], self.line, self.column)
            else:
                list_pks = []
                for col in pk_col_name:
                    list_pks.append(col.name)

                table_update.columns = headers
                pk_list = table_update[list_pks].values.tolist()
                print(pk_list)
                for pk in pk_list:
                    DataController().update(self.table, d, [
                        pk], self.line, self.column)

        else:
            if self.params is not list:
                self.params = [self.params]
            for option in self.params:
                if isinstance(option, Where):
                    table_update.columns = headers
                    storage_columns(table_cont, headers,
                                    self.line, self.column)
                    storage_table(table_cont, headers, self.table,
                                  self.line, self.column)
                    table_result = option.process(
                        instruction, table_update, self.table)

                    pk_col_name = TypeChecker().searchColPrimaryKey(table_tp)
                    if pk_col_name == []:  # NO HAY LLAVE PRIMARIA
                        pk_list = table_result.index.to_list()
                        print(pk_list)
                        for pk in pk_list:
                            if type(pk) is list:
                                DataController().update(self.table, d, pk, self.line, self.column)
                            else:
                                DataController().update(self.table, d, [pk], self.line, self.column)
                    else:
                        table_result.columns = headers
                        list_pks = []
                        for col in pk_col_name:
                            list_pks.append(col.name)

                        pk_list = table_result[list_pks].values.tolist()
                        print(pk_list)
                        for pk in pk_list:
                            if type(pk) is list:
                                DataController().update(self.table, d, pk, self.line, self.column)
                            else:
                                DataController().update(self.table, d, [pk], self.line, self.column)
        return None