예제 #1
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,0,0)
        headers = TypeChecker().searchColumnHeadings(table_tp)
        table_update = pd.DataFrame(table_cont)
        table_update.columns = headers

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

        for column in self.arr_columns_vals:
            tuplas.append(column.process(instruction))
        d = {}
        for t in tuplas:
            if not t[0] in headers:
                print("Columna no existe --- ERROR")
                break
            else:
                d[ headers.index(t[0]) ] = t[1].value

        print("DICTIONARY")
        print(d)
        return None

        if self.params == None: #CAMBIAR TODOS LOS REGISTROS DE LA TABLA
            pk_col_name = TypeChecker().searchColPrimaryKey(table_tp).name
            pk_list = table_update[[pk_col_name]].to_numpy()
            print(pk_list)

            for pk in pk_list:
                DataController().update(self.table.value, d, pk, 0 , 0)
        else:
            for option in self.params:
                if isinstance(option, Where):
                    table_update.query(option.condition.alias)
                    break
예제 #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