Ejemplo n.º 1
0
    def ejecutar(self):
        left_value = self.left.ejecutar()
        right_value = ""
        tipo_dominante = left_value.tipo

        if self.right != None:
            right_value = self.right.ejecutar()
            tipo_dominante = self.tipo_dominante(left_value.tipo.value, right_value.tipo.value)        

        resultado = ""        

        if self.tipo_oper == operacion_logica.AND:
            if tipo_dominante == tipo_primitivo.BOOLEAN:
                resultado = retorno(left_value.valor and right_value.valor, tipo_primitivo.BOOLEAN)
            else:
                errores.append(nodo_error(self.line, self.column, 'Solo se pueden operar tipos booleanos', 'Semántico'))
        elif self.tipo_oper == operacion_logica.OR:
            if tipo_dominante == tipo_primitivo.BOOLEAN:
                resultado = retorno(left_value.valor or right_value.valor, tipo_primitivo.BOOLEAN)
            else:
                errores.append(nodo_error(self.line, self.column, 'Solo se pueden operar tipos booleanos', 'Semántico'))
        elif self.tipo_oper == operacion_logica.NOT:
            if tipo_dominante == tipo_primitivo.BOOLEAN:
                resultado = retorno(not right_value.valor, tipo_primitivo.BOOLEAN)
            else:
                errores.append(nodo_error(self.line, self.column, 'Solo se pueden operar tipos booleanos', 'Semántico'))
                
        return resultado
Ejemplo n.º 2
0
    def ejecutar(self, list_tb):
        #RETORNAR TABLA COMPLETA CON INDICE DE TABLA
        actualDB = get_actual_use()

        #BUSCAR TABLA CON COLUMNA
        col_item = ts.get_col(actualDB, self.table, self.columna)
        if col_item != None:
            getdata = funciones.extractTable(actualDB, self.table)
            index_col = ts.get_pos_col(actualDB, self.table, self.columna)
            encabezados = ts.field_names(actualDB, self.table)
            return retorno(getdata,
                           col_item.tipo,
                           True,
                           index_col,
                           encabezados=encabezados)

        #BUSCAR TABLA CON ALIAS
        alias_tb = ts.get_alias(self.table)
        if alias_tb != None:
            item_col = ts.get_col(actualDB, alias_tb, self.columna)
            getdata = funciones.extractTable(actualDB, alias_tb)
            index_col = ts.get_pos_col(actualDB, alias_tb, self.columna)
            encabezados = ts.field_names(actualDB, alias_tb)
            return retorno(getdata, item_col.tipo, True, index_col,
                           encabezados)

        errores.append(
            nodo_error(
                self.line, self.column,
                'ERROR - No se puede extraer la data de ' + self.table + '.' +
                self.columna, 'Semántico'))
        add_text('ERROR - No se puede extraer la data de ' + self.table + '.' +
                 self.columna + '\n')
Ejemplo n.º 3
0
    def ejecutar(self, list_tb):
        actualDB = get_actual_use()

        #RETORNAR LA TABLA COMPLETA CON INDICE DE COLUMNA
        for item in list_tb:
            col_item = ts.get_col(actualDB, item, self.valor)

            if col_item != None:
                encabezados=ts.field_names(actualDB,item)
                getdata = funciones.extractTable(actualDB,item)
                index_col = ts.get_pos_col(actualDB, item, self.valor)                
                return retorno(getdata, col_item.tipo, True, index_col,encabezados)

        #BUSCAR LA TABLA POR ALIAS
        alias_tb = ts.get_alias(self.valor)
        if alias_tb != None:
            encabezados = ts.field_names(actualDB, alias_tb)
            getdata = funciones.extractTable(actualDB, alias_tb)
            return retorno(getdata, tipo_primitivo.TABLA, True, encabezados)
            
        
        #RETORNAR LA TABLA COMPLETA SIN INDICE DE COLUMNA
        extract_tb = ts.get_tb(actualDB, self.valor)
        if extract_tb != None:
            encabezados=ts.field_names(actualDB,self.valor)
            getdata = funciones.extractTable(actualDB,self.valor)
            return retorno(getdata, tipo_primitivo.TABLA, True, encabezados)

        errores.append(nodo_error(self.line, self.column, 'ERROR - No se puede extraer la data del id ' + self.valor, 'Semántico'))
        add_text('ERROR - No se puede extraer la data del id ' + self.valor + '\n')
        return retorno(-1, tipo_primitivo.ERROR)
Ejemplo n.º 4
0
    def ejecutar(self, imprimir=None):
        id_db = get_actual_use() 
        salidaTabla = PrettyTable()
        encabezados=[]
        registro = []
        list_campo = []
        for dato in self.expresiones:
            if dato != None:
                auxDato=dato.ejecutar(id_db)
                list_campo.append(auxDato.valor)
            salidaTabla.add_column(auxDato.query,list_campo)
            list_campo.clear()
        
        add_text('\n')
        add_text(salidaTabla)
        add_text('\n')


        return retorno(registro,encabezados)
Ejemplo n.º 5
0
    def ejecutar(self):
        left_value = self.left.ejecutar()
        right_value = self.right.ejecutar()

        if self.tipo_oper == operacion_relacional.IGUALDAD:
            return retorno(left_value.valor == right_value.valor,
                           tipo_primitivo.BOOLEAN)
        elif self.tipo_oper == operacion_relacional.DESIGUALDAD:
            return retorno(left_value.valor != right_value.valor,
                           tipo_primitivo.BOOLEAN)
        elif self.tipo_oper == operacion_relacional.MAYOR:
            return retorno(left_value.valor > right_value.valor,
                           tipo_primitivo.BOOLEAN)
        elif self.tipo_oper == operacion_relacional.MENOR:
            return retorno(left_value.valor < right_value.valor,
                           tipo_primitivo.BOOLEAN)
        elif self.tipo_oper == operacion_relacional.MAYOR_IGUAL:
            return retorno(left_value.valor >= right_value.valor,
                           tipo_primitivo.BOOLEAN)
        elif self.tipo_oper == operacion_relacional.MENOR_IGUAL:
            return retorno(left_value.valor <= right_value.valor,
                           tipo_primitivo.BOOLEAN)
Ejemplo n.º 6
0
    def ejecutar(self, list_tb):
        left_value = self.left.ejecutar(list_tb)
        right_value = self.right.ejecutar(list_tb)

        #IGUALDAD
        if self.tipo_oper == operacion_relacional.IGUALDAD:
            if left_value.query == True and right_value.query == True:                
                pass
            elif left_value.query == True:
                registros = []
                for item in left_value.valor:
                    if item[left_value.index_col] == right_value.valor:
                        registros.append(item)

                return retorno(registros, tipo_primitivo.TABLA, True, left_value.index_col ,encabezados=left_value.encabezados)
            elif right_value.query == True:
                registros = []
                for item in right_value.valor:
                    if item[right_value.index_col] == left_value.valor:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, right_value.index_col, encabezados=right_value.encabezados)
            else:
                return retorno(left_value.valor == right_value.valor, tipo_primitivo.BOOLEAN)
        # DESIGUALDAD
        elif self.tipo_oper == operacion_relacional.DESIGUALDAD:
            if left_value.query == True and right_value.query == True:                
                pass
            elif left_value.query == True:
                registros = []
                for item in left_value.valor:
                    if item[left_value.index_col] != right_value.valor:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, left_value.index_col, encabezados=left_value.encabezados)
            elif right_value.query == True:
                registros = []
                for item in right_value.valor:
                    if left_value.valor != item[right_value.index_col]:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, right_value.index_col, encabezados=right_value.encabezados)
            else:
                return retorno(left_value.valor == right_value.valor, tipo_primitivo.BOOLEAN)
        #MAYOR
        elif self.tipo_oper == operacion_relacional.MAYOR:
            if left_value.query == True and right_value.query == True:                
                pass
            elif left_value.query == True:
                registros = []
                for item in left_value.valor:
                    if item[left_value.index_col] > right_value.valor:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, left_value.index_col, encabezados=left_value.encabezados)
            elif right_value.query == True:
                registros = []
                for item in right_value.valor:
                    if left_value.valor > item[right_value.index_col]:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, right_value.index_col, encabezados=right_value.encabezados)
            else:
                return retorno(left_value.valor > right_value.valor, tipo_primitivo.BOOLEAN)
        #MENOR
        elif self.tipo_oper == operacion_relacional.MENOR:
            if left_value.query == True and right_value.query == True:                
                pass
            elif left_value.query == True:
                registros = []
                for item in left_value.valor:
                    if item[left_value.index_col] >= right_value.valor:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, left_value.index_col, encabezados=left_value.encabezados)
            elif right_value.query == True:
                registros = []
                for item in right_value.valor:
                    if left_value.valor >= item[right_value.index_col]:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, right_value.index_col, encabezados=right_value.encabezados)
            else:
                return retorno(left_value.valor < right_value.valor, tipo_primitivo.BOOLEAN)
        # MAYOR IGUAL
        elif self.tipo_oper == operacion_relacional.MAYOR_IGUAL:
            if left_value.query == True and right_value.query == True:                
                pass
            elif left_value.query == True:
                registros = []
                for item in left_value.valor:
                    if item[left_value.index_col] < right_value.valor:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, left_value.index_col, encabezados=left_value.encabezados)
            elif right_value.query == True:
                registros = []
                for item in right_value.valor:
                    if left_value.valor < item[right_value.index_col]:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, right_value.index_col, encabezados=right_value.encabezados)
            else:
                return retorno(left_value.valor >= right_value.valor, tipo_primitivo.BOOLEAN)
        
        #MENOR IGUAL
        elif self.tipo_oper == operacion_relacional.MENOR_IGUAL:
            if left_value.query == True and right_value.query == True:                
                pass
            elif left_value.query == True:
                registros = []
                for item in left_value.valor:
                    if item[left_value.index_col] > right_value.valor:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, left_value.index_col, encabezados=left_value.encabezados)
            elif right_value.query == True:
                registros = []
                for item in right_value.valor:
                    if left_value.valor > item[right_value.index_col]:
                        registros.append(item)
                return retorno(registros, tipo_primitivo.TABLA, True, right_value.index_col, encabezados=right_value.encabezados)
            else:
                return retorno(left_value.valor <= right_value.valor, tipo_primitivo.BOOLEAN)
Ejemplo n.º 7
0
    def ejecutar(self, list_db):
        today = date.today()
        now = datetime.now()
        aux = 0
        numero = self.expresiones.valor
        numero1 = 0
        if self.expresiones1 != None:
            numero1 = self.expresiones1.valor

        if self.alias == None:
            self.alias = "Resultado"
        print(self.agrupacion)
        if str(self.agrupacion).lower() == "factorial":
            aux = m.factorial(numero)
        elif str(self.agrupacion).lower() == "cbrt":
            aux = round(numero**(1 / 3))
        elif str(self.agrupacion).lower() == "abs":
            aux = abs(numero)
        elif str(self.agrupacion).lower() == "ceil":
            aux = int(numero + 1)
        elif str(self.agrupacion).lower() == "ceiling":
            aux = int(numero + 1)
        elif str(self.agrupacion).lower() == "degrees":
            aux = numero * (180 / m.pi)
        elif str(self.agrupacion).lower() == "div":
            aux = int(numero / numero1)
        elif str(self.agrupacion).lower() == "exp":
            aux = m.exp(numero)
        elif str(self.agrupacion).lower() == "floor":
            aux = int(numero)
        elif str(self.agrupacion).lower() == "gcd":
            aux = m.gcd(numero, numero1)
        elif str(self.agrupacion).lower() == "ln":
            aux = m.log(numero, m.e)
        elif str(self.agrupacion).lower() == "log":
            aux = m.log10(numero)
        elif str(self.agrupacion).lower() == "mod":
            aux = numero % numero1
        elif str(self.agrupacion).lower() == "pi":
            aux = m.pi
        elif str(self.agrupacion).lower() == "power":
            aux = numero**numero1
        elif str(self.agrupacion).lower() == "radians":
            aux = m.radians(numero)
        elif str(self.agrupacion).lower() == "round":
            aux = round(numero)
        elif str(self.agrupacion).lower() == "sing":
            aux = -1 if numero < 0 else 1
        elif str(self.agrupacion).lower() == "sqrt":
            aux = m.sqrt(numero)
        elif str(self.agrupacion).lower() == "width_bucket":
            aux = r.randint(1, 3)
        elif str(self.agrupacion).lower() == "trunc":
            aux = int(numero)
        elif str(self.agrupacion).lower() == "random":
            aux = r.random()
        elif str(self.agrupacion).lower() == "acos":
            aux = m.acos(numero)
        elif str(self.agrupacion).lower() == "acosd":
            aux = m.degrees(acos(numero))
        elif str(self.agrupacion).lower() == "asin":
            aux = m.asin(numero)
        elif str(self.agrupacion).lower() == "asind":
            aux = m.degrees(asin(numero))
        elif str(self.agrupacion).lower() == "atan":
            aux = m.atan(numero)
        elif str(self.agrupacion).lower() == "atand":
            aux = m.degrees(atan(numero))
        elif str(self.agrupacion).lower() == "atan2":
            aux = m.atan2(numero, numero1)
        elif str(self.agrupacion).lower() == "atan2d":
            aux = m.degrees(atan2(numero, numero1))
        elif str(self.agrupacion).lower() == "cos":
            aux = m.cos(numero)
        elif str(self.agrupacion).lower() == "cosd":
            aux = m.degrees(cos(numero))
        elif str(self.agrupacion).lower() == "cot":
            aux = (m.cos(numero) / m.sin(numero))
        elif str(self.agrupacion).lower() == "cotd":
            aux = m.degrees(cot(numero))
        elif str(self.agrupacion).lower() == "sin":
            aux = m.sin(numero)
        elif str(self.agrupacion).lower() == "sind":
            aux = m.degrees(sin(numero))
        elif str(self.agrupacion).lower() == "tan":
            aux = m.tan(numero)
        elif str(self.agrupacion).lower() == "tand":
            aux = m.degrees(tan(numero))
        elif str(self.agrupacion).lower() == "sinh":
            aux = m.sinh(numero)
        elif str(self.agrupacion).lower() == "cosh":
            aux = m.cosh(numero)
        elif str(self.agrupacion).lower() == "tanh":
            aux = m.tanh(numero)
        elif str(self.agrupacion).lower() == "asinh":
            aux = m.asinh(numero)
        elif str(self.agrupacion).lower() == "acosh":
            aux = m.acosh(numero)
        elif str(self.agrupacion).lower() == "atanh":
            aux = m.atanh(numero)
        elif str(self.agrupacion).lower() == "now":
            aux = now.strftime("%Y-%m-%d %H:%M:%S")
        elif str(self.agrupacion).lower() == "timestamp":
            aux = now.strftime("%Y-%m-%d %H:%M:%S")
        elif str(self.agrupacion).lower() == "current_date":
            aux = now.strftime("%Y-%m-%d")
        elif str(self.agrupacion).lower() == "current_time":
            aux = now.strftime("%H:%M:%S")
        elif str(self.agrupacion).lower() == "date_part":
            aux = now.strftime("%H:%M:%S")
            if numero == "hour" or numero == "hours":
                aux_time = str(numero1).split()
                aux = aux_time[0]
            elif numero == "minutes" or numero == "minute":
                aux_time = str(numero1).split()
                aux = aux_time[2]
            elif numero == "seconds" or numero == "second":
                aux_time = str(numero1).split()
                aux = aux_time[4]
            else:
                aux = "No se encontro"
        elif str(self.agrupacion).lower() == "extract":
            x_time = str(numero1).split()
            y_time = x_time[0].split("-")
            z_time = x_time[1].split(":")
            if numero == "year":
                aux = y_time[0]
            elif numero == "month":
                aux = y_time[1]
            elif numero == "day":
                aux = y_time[2]
            elif numero == "hour":
                aux = z_time[0]
            elif numero == "minute":
                aux = z_time[1]
            elif numero == "second":
                aux = z_time[2]
        elif str(self.agrupacion).lower() == "substring" or str(
                self.agrupacion).lower() == "substr":
            aux_sub = ""
            for x in range(numero1):
                aux_sub += numero[x]
            aux = aux_sub
        elif str(self.agrupacion).lower() == "length":
            aux = len(numero)
        elif str(self.agrupacion).lower() == "trim":
            aux = str(numero).strip()
        elif str(self.agrupacion).lower() == "md5":
            aux = hashlib.md5(numero.encode()).hexdigest()
        elif str(self.agrupacion).lower() == "sha256":
            aux = hashlib.sha256(numero.encode()).hexdigest()
        elif str(self.agrupacion).lower() == "decode":
            aux = numero
        elif str(self.agrupacion).lower() == "encode":
            aux = numero
        elif str(self.agrupacion).lower() == "get_byte":
            aux = ord(str(numero[numero1]))
        elif str(self.agrupacion).lower() == "set_byte":
            aux = numero
        elif str(self.agrupacion).lower() == "convert":
            aux = numero

        self.valor = aux
        print(self.valor)
        return retorno(self.valor, self.tipo, self.alias)
Ejemplo n.º 8
0
 def ejecutar(self, list_tb):
     return retorno(self.valor, self.tipo)
Ejemplo n.º 9
0
 def ejecutar(self):
     return retorno(self.valor, self.tipo)
Ejemplo n.º 10
0
    def ejecutar(self):
        left_value = self.left.ejecutar()
        right_value = self.right.ejecutar()

        resultado = ""

        tipo_dominante = self.tipo_dominante(left_value.tipo.value,
                                             right_value.tipo.value)

        if self.tipo_oper == operacion_aritmetica.SUMA:
            if tipo_dominante == tipo_primitivo.SMALLINT or tipo_dominante == tipo_primitivo.INTEGER or tipo_dominante == tipo_primitivo.BIGINT or tipo_dominante == tipo_primitivo.DECIMAL or tipo_dominante == tipo_primitivo.REAL or tipo_dominante == tipo_primitivo.DOUBLE_PRECISION or tipo_dominante == tipo_primitivo.MONEY:
                resultado = retorno(left_value.valor + right_value.valor,
                                    tipo_dominante)
            else:
                errores.append(
                    nodo_error(
                        self.line, self.column,
                        'No se pueden sumar los tipos: ' +
                        self.get_str_tipo(left_value.tipo) + ' + ' +
                        self.get_str_tipo(right_value.tipo), 'Semántico'))
        elif self.tipo_oper == operacion_aritmetica.RESTA:
            if tipo_dominante == tipo_primitivo.SMALLINT or tipo_dominante == tipo_primitivo.INTEGER or tipo_dominante == tipo_primitivo.BIGINT or tipo_dominante == tipo_primitivo.DECIMAL or tipo_dominante == tipo_primitivo.REAL or tipo_dominante == tipo_primitivo.DOUBLE_PRECISION or tipo_dominante == tipo_primitivo.MONEY:
                resultado = retorno(left_value.valor - right_value.valor,
                                    tipo_dominante)
            else:
                errores.append(
                    nodo_error(
                        self.line, self.column,
                        'No se pueden restar los tipos: ' +
                        self.get_str_tipo(left_value.tipo) + ' - ' +
                        self.get_str_tipo(right_value.tipo), 'Semántico'))
        elif self.tipo_oper == operacion_aritmetica.DIVISION:
            if tipo_dominante == tipo_primitivo.SMALLINT or tipo_dominante == tipo_primitivo.INTEGER or tipo_dominante == tipo_primitivo.BIGINT or tipo_dominante == tipo_primitivo.DECIMAL or tipo_dominante == tipo_primitivo.REAL or tipo_dominante == tipo_primitivo.DOUBLE_PRECISION or tipo_dominante == tipo_primitivo.MONEY:
                if right_value.valor != 0:
                    resultado = retorno(left_value.valor / right_value.valor,
                                        tipo_dominante)
                else:
                    errores.append(
                        nodo_error(self.line, self.column,
                                   'El valor del divisor debe ser mayor a 0',
                                   'Semántico'))
            else:
                errores.append(
                    nodo_error(
                        self.line, self.column,
                        'No se pueden dividir los tipos: ' +
                        self.get_str_tipo(left_value.tipo) + ' + ' +
                        self.get_str_tipo(right_value.tipo), 'Semántico'))
        elif self.tipo_oper == operacion_aritmetica.MULTIPLICACION:
            if tipo_dominante == tipo_primitivo.SMALLINT or tipo_dominante == tipo_primitivo.INTEGER or tipo_dominante == tipo_primitivo.BIGINT or tipo_dominante == tipo_primitivo.DECIMAL or tipo_dominante == tipo_primitivo.REAL or tipo_dominante == tipo_primitivo.DOUBLE_PRECISION or tipo_dominante == tipo_primitivo.MONEY:
                resultado = retorno(left_value.valor * right_value.valor,
                                    tipo_dominante)
            else:
                errores.append(
                    nodo_error(
                        self.line, self.column,
                        'No se pueden multiplicar los tipos: ' +
                        self.get_str_tipo(left_value.tipo) + ' + ' +
                        self.get_str_tipo(right_value.tipo), 'Semántico'))
        elif self.tipo_oper == operacion_aritmetica.MODULO:
            if tipo_dominante == tipo_primitivo.SMALLINT or tipo_dominante == tipo_primitivo.INTEGER or tipo_dominante == tipo_primitivo.BIGINT or tipo_dominante == tipo_primitivo.DECIMAL or tipo_dominante == tipo_primitivo.REAL or tipo_dominante == tipo_primitivo.DOUBLE_PRECISION or tipo_dominante == tipo_primitivo.MONEY:
                resultado = retorno(left_value.valor % right_value.valor,
                                    tipo_dominante)
            else:
                errores.append(
                    nodo_error(
                        self.line, self.column,
                        'No se pueden usar modulo con los tipos: ' +
                        self.get_str_tipo(left_value.tipo) + ' + ' +
                        self.get_str_tipo(right_value.tipo), 'Semántico'))
        elif self.tipo_oper == operacion_aritmetica.POTENCIA:
            if tipo_dominante == tipo_primitivo.SMALLINT or tipo_dominante == tipo_primitivo.INTEGER or tipo_dominante == tipo_primitivo.BIGINT or tipo_dominante == tipo_primitivo.DECIMAL or tipo_dominante == tipo_primitivo.REAL or tipo_dominante == tipo_primitivo.DOUBLE_PRECISION or tipo_dominante == tipo_primitivo.MONEY:
                resultado = retorno(pow(left_value.valor, right_value.valor),
                                    tipo_dominante)
            else:
                errores.append(
                    nodo_error(
                        self.line, self.column,
                        'No se puede potenciar los tipos: ' +
                        self.get_str_tipo(left_value.tipo) + ' + ' +
                        self.get_str_tipo(right_value.tipo), 'Semántico'))
        return resultado
Ejemplo n.º 11
0
    def ejecutar(self, list_id):
        #try:
        id_db = get_actual_use()

        indice_inferior = self.expresiones2.ejecutar(list_id)
        if indice_inferior.tipo == tipo_primitivo.ERROR:
            errores.append(nodo_error(self.line, self.column, 'ERROR - No puedes validar este tipo', 'Semántico'))
            add_text('ERROR - No puedes validar este tipo\n')
            return retorno(-1, tipo_primitivo.ERROR)

        indice_superior = self.expresiones3.ejecutar(list_id)
        if indice_superior.tipo == tipo_primitivo.ERROR:
            errores.append(nodo_error(self.line, self.column, 'ERROR - No puedes validar este tipo', 'Semántico'))
            add_text('ERROR - No puedes validar este tipo\n')
            return retorno(-1, tipo_primitivo.ERROR)

        evaluar = self.expresiones1.ejecutar(list_id)
        if evaluar.tipo == tipo_primitivo.ERROR:
            errores.append(nodo_error(self.line, self.column, 'ERROR - No puedes validar este tipo', 'Semántico'))
            add_text('ERROR - No puedes validar este tipo\n')
            return retorno(-1, tipo_primitivo.ERROR)

        registros_resultado = []

        #CONOCER SI ES LISTA DE REGISTROS 
        #EVALUAR ES UNA TABLA
        if evaluar.query == True:
            #BETWEEN
            if self.between.lower() == 'between':
                for registro in evaluar.valor:
                    try:
                        #ANALIZAR LIMITE INFERIOR
                        #LIMITE INFERIOR ES UNA TABLA
                        if indice_inferior.query == True:
                            if indice_inferior.valor[indice_inferior.index_col] > registro:
                                #LIMITE SUPERIOR ES UNA TABLA
                                if indice_superior.query == True:
                                    if registro < indice_superior.valor[indice_superior.index_col]:
                                        registros_resultado.append(registro)
                                #LIMITE SUPERIOR NO ES UNA TABLA
                                else:
                                    if registro < indice_superior.valor:
                                        registros_resultado.append(registro)
                        #LIMITE INFERIOR NO ES UNA TABLA
                        else:
                            
                            if indice_inferior.valor > registro:
                                #LIMITE SUPERIOR ES UNA TABLA
                                if indice_superior.query == True:
                                    if registro < indice_superior.valor[indice_superior.index_col]:
                                        registros_resultado.append(registro)
                                #LIMITE SUPERIOR NO ES UNA TABLA
                                else:
                                    print("superior no es tabla")
                                    if registro < indice_superior.valor:
                                        print("encontramos dato")
                                        registros_resultado.append(registro)
                    except:
                        pass
            #NOT BETWEEN
            else:
                for registro in evaluar.valor:
                    try:
                        #ANALIZAR LIMITE INFERIOR
                        #LIMITE INFERIOR ES UNA TABLA
                        if indice_inferior.query == True:
                            if indice_inferior.valor[indice_inferior.index_col] < registro:
                                registros_resultado.append(registro)
                            else:
                                #LIMITE SUPERIOR ES UNA TABLA
                                if indice_superior.query == True:
                                    if registro > indice_superior.valor[indice_superior.index_col]:
                                        registros_resultado.append(registro)
                                #LIMITE SUPERIOR NO ES UNA TABLA
                                else:
                                    if registro > indice_superior.valor:
                                        registros_resultado.append(registro)
                        #LIMITE INFERIOR NO ES UNA TABLA
                        else:
                            if indice_inferior.valor < registro:
                                registros_resultado.append(registro)
                            else:
                                #LIMITE SUPERIOR ES UNA TABLA
                                if indice_superior.query == True:
                                    if registro > indice_superior.valor[indice_superior.index_col]:
                                        registros_resultado.append(registro)
                                #LIMITE SUPERIOR NO ES UNA TABLA
                                else:
                                    if registro > indice_superior.valor:
                                        registros_resultado.append(registro)
                    except:
                        pass
        #EVALUAR NO ES TABLA
        else:
                            
            #BETWEEN
            if self.between.lower() == 'between':
                #ANALIZAR LIMITE INFERIOR
                #LIMITE INFERIOR ES UNA TABLA
                if indice_inferior.query == True:
                    errores.append(nodo_error(self.line, self.column, 'ERROR - No puedes validar este tipo', 'Semántico'))
                    add_text('ERROR - No puedes validar este tipo\n')
                    return retorno(-1, tipo_primitivo.ERROR)
                #LIMITE INFERIOR NO ES UNA TABLA
                else:
                    if indice_inferior.valor > registro:
                        #LIMITE SUPERIOR ES UNA TABLA
                        if indice_superior.query == True:
                            errores.append(nodo_error(self.line, self.column, 'ERROR - No puedes validar este tipo', 'Semántico'))
                            add_text('ERROR - No puedes validar este tipo\n')
                            return retorno(-1, tipo_primitivo.ERROR)
                        #LIMITE SUPERIOR NO ES UNA TABLA
                        else:
                            if registro < indice_superior.valor:
                                registros_resultado.append(registro)
            
            #NOT BETWEEN
            else:
                #ANALIZAR LIMITE INFERIOR
                #LIMITE INFERIOR ES UNA TABLA
                if indice_inferior.query == True:
                    errores.append(nodo_error(self.line, self.column, 'ERROR - No puedes validar este tipo', 'Semántico'))
                    add_text('ERROR - No puedes validar este tipo\n')
                    return retorno(-1, tipo_primitivo.ERROR)
                #LIMITE INFERIOR NO ES UNA TABLA
                else:
                    if indice_inferior.valor < registro:
                        registros_resultado.append(registro)
                    else:
                        #LIMITE SUPERIOR ES UNA TABLA
                        if indice_superior.query == True:
                            errores.append(nodo_error(self.line, self.column, 'ERROR - No puedes validar este tipo', 'Semántico'))
                            add_text('ERROR - No puedes validar este tipo\n')
                            return retorno(-1, tipo_primitivo.ERROR)
                        #LIMITE SUPERIOR NO ES UNA TABLA
                        else:
                            if registro > indice_superior.valor:
                                registros_resultado.append(registro)

        return registros_resultado
Ejemplo n.º 12
0
 def ejecutar(self):
     return retorno(self.expresiones, self.asc_desc)
Ejemplo n.º 13
0
    def ejecutar(self):
        #try:
        actual_db = get_actual_use()

        valores_iniciales = []
        lista_aux = []

        for item in self.lista:
            valores_iniciales.append(item.ejecutar([]))

        retornos = []
        index_id = 0
        if self.cols_id != None:
            #Extraer colummas de la tabla
            columnas_table = ts.get_cols(actual_db, self.dato)

            if columnas_table != None:
                for item_columna in columnas_table:
                    if index_id < len(self.cols_id):
                        if self.cols_id[index_id] == item_columna.id_:
                            lista_aux.append(self.lista[index_id])
                            retornos.append(valores_iniciales[index_id])
                            index_id += 1
                        else:
                            lista_aux.append(
                                primitivo(self.line, self.column, 'NULL',
                                          tipo_primitivo.NULL,
                                          self.num_nodo + 1000000000))
                            retornos.append(
                                retorno('NULL', tipo_primitivo.NULL))
                    else:
                        lista_aux.append(
                            primitivo(self.line, self.column, 'NULL',
                                      tipo_primitivo.NULL,
                                      self.num_nodo + 1000000000))
                        retornos.append(retorno('NULL', tipo_primitivo.NULL))
            else:
                errores.append(
                    nodo_error(
                        self.line, self.column,
                        'E-42P10 invalid column reference: Cannot extract columns to insert data',
                        'Semántico'))
                add_text(
                    'E-42P10 invalid column reference: Cannot extract columns to insert data.\n'
                )
        else:
            retornos = valores_iniciales

        valores = []
        for item in retornos:
            valores.append(item.valor)

        tipo_dominante = 17

        #Validar tipos de dato de insert en columna y dato
        if len(retornos) == ts.count_columns(actual_db, self.dato):
            count_pos = 0
            for value in retornos:

                if value.tipo != tipo_primitivo.NULL:
                    columna = ts.get_col_by_pos(actual_db, self.dato,
                                                count_pos)
                    tipo_dominante = tipos_tabla[value.tipo.value][
                        columna.tipo.value]

                    if tipo_dominante != columna.tipo:
                        errores.append(
                            nodo_error(
                                self.line, self.column,
                                'E-42809 wrong object type: You cannot insert a data type '
                                + self.get_str_tipo(value.tipo) +
                                ' in a column of type ' +
                                self.get_str_tipo(columna.tipo), 'Semántico'))
                        add_text(
                            'E-42809 wrong object type: You cannot insert a data type '
                            + self.get_str_tipo(value.tipo) +
                            ' in a column of type ' +
                            self.get_str_tipo(columna.tipo) + '\n')
                        return

                    count_pos += 1

                    #Validar el tamaño correcto
                    if tipo_dominante == tipo_primitivo.CHAR or tipo_dominante == tipo_primitivo.VARCHAR:
                        if columna.size < len(value.valor):
                            errores.append(
                                nodo_error(
                                    self.line, self.column,
                                    'E-22015 interval field overflow: Data size exceeded '
                                    + value.valor, 'Semántico'))
                            add_text(
                                'E-22015 interval field overflow: Data size exceeded '
                                + value.valor + '\n')
                            return

                else:
                    #Omitir NULL, para validar despues las restricciones de columnas
                    count_pos += 1
        else:
            errores.append(
                nodo_error(
                    self.line, self.column,
                    'E-22005 error in assignment: Columns out of bounds',
                    'Semántico'))
            add_text('E-22005 error in assignment: Columns out of bounds\n')
            return

        #Validar restricciones de columnas
        index_col = 0
        for value in valores:
            col_actual = ts.get_col_by_pos(actual_db, self.dato, index_col)

            if col_actual.condiciones != None:
                for restriccion in col_actual.condiciones:
                    valido = None

                    if isinstance(restriccion, unique_simple):
                        pos_col = ts.get_pos_col(actual_db, self.dato,
                                                 col_actual.id_)
                        valido = restriccion.ejecutar(self.dato, value,
                                                      pos_col)
                    elif isinstance(restriccion, condicion_simple):
                        pos_col = ts.get_pos_col(actual_db, self.dato,
                                                 col_actual.id_)
                        valido = restriccion.ejecutar(value, pos_col)

                    if isinstance(valido, nodo_error):
                        errores.append(valido)
                        salida_consola = valido.valor + '\n'
                        add_text(salida_consola)
                        return
                    elif valido != None:
                        #Encontramos un cambio para el dato en el default
                        valores[index_col] = valido

            index_col += 1

        aux_insert = funciones.insert(actual_db, self.dato, valores)
        # Valor de retorno: 0 operación exitosa, 1 error en la operación, 2 database no existente, 3 table no existente, 4 llave primaria duplicada, 5 columnas fuera de límites.

        if aux_insert == 0:
            add_text("M-00000 successful completion: Row inserted correctly\n")
        elif aux_insert == 1:
            errores.append(
                nodo_error(
                    self.line, self.column,
                    'E-22005 error in assignment: Could not insert row',
                    'Semántico'))
            add_text('E-22005 error in assignment: Could not insert row\n')
        elif aux_insert == 2:
            errores.append(
                nodo_error(
                    self.line, self.column,
                    'E-22005 error in assignment: There is no database with the following ID -> '
                    + actual_db, 'Sémantico'))
            add_text(
                'E-22005 error in assignment:\nThere is no database with the following ID ->'
                + actual_db + '\n')
        elif aux_insert == 3:
            errores.append(
                nodo_error(
                    self.line, self.column,
                    'E-22005 error in assignment: The table with the following ID does not exist -> '
                    + self.dato, 'Semántico'))
            add_text(
                'E-22005 error in assignment: The table with the following ID does not exist -> '
                + self.dato + '\n')
        elif aux_insert == 4:
            errores.append(
                nodo_error(
                    self.line, self.column,
                    'E-22005 error in assignment: Duplicate primary key',
                    'Semántico'))
            add_text('E-22005 error in assignment: Duplicate primary key\n')
        elif aux_insert == 5:
            errores.append(
                nodo_error(
                    self.line, self.column,
                    'E-22005 error in assignment: Columns out of bounds',
                    'Semántico'))
            add_text('E-22005 error in assignment: Columns out of bounds\n')
Ejemplo n.º 14
0
    def ejecutar(self, imprimir=None):
        try:
            for id_item in self.list_tables:
                if isinstance(id_item, alias_item):
                    id_item.ejecutar([])

            id_db = get_actual_use()
            salidaTabla = PrettyTable()
            encabezados=[]

            registro = []
            registro_aux = []

            if self.donde == None:
                for tabla in self.list_tables:
                    data_table = funciones.extractTable(id_db,tabla)
                    registro=data_table
                    encabezados=ts.field_names(id_db,tabla)
            #si viene where
            else:
                data_were = self.donde.ejecutar(self.list_tables)
                print(data_were)
                if data_were.tipo != tipo_primitivo.ERROR:
                    encabezados = data_were.encabezados
                    registro=data_were.valor
                else:
                    errores.append(nodo_error(self.line, self.column, 'ERROR - No se pudo ejecutar select', 'Semántico'))
                    add_text('ERROR - No se pudo ejecutar select\n')

            #Si viene GroupBy

            if self.groupby != None:
                lista_groupBy = self.groupby.ejecutar()
                print(str(lista_groupBy))
                index_G = self.retornador_index(lista_groupBy[0],encabezados)
                print(str(index_G))

                registro_columnas = []

                for busqueda in registro:

                    contador_aux = 0


                    for aux in busqueda:

                        if index_G == contador_aux:
                            if self.existencia_grupby(busqueda,registro_columnas,index_G):
                                registro_columnas.append(busqueda)

                        contador_aux += 1
                print(registro_columnas)
                registro=registro_columnas

            #Si viene OrderBy
            if self.orderby != None:
                auxOrder_by = self.orderby.ejecutar()
                indexG=self.retornador_index(auxOrder_by.valor[0],encabezados)

                if auxOrder_by.tipo == 'ASC':
                    registro = sorted(registro, key=lambda i: str(i[indexG]).lower())
                elif auxOrder_by.tipo == 'DESC':
                    registro = sorted(registro, key=lambda i: str(i[indexG]).lower(), reverse=True)

            if self.lista_cols != '*':
                listCampos2 = []
                auxEncabezados=[]
                for col in self.lista_cols:
                    contador = -1
                    for campo in encabezados:
                        listCampos2.clear()
                        contador += 1
                        if (col.valor == campo):
                            auxEncabezados.append(col.valor)
                            aux = columnaId([],col.valor)
                            for col2 in registro:
                                listCampos2.append(col2[contador])
                                aux.lista.append(col2[contador])
                            salidaTabla.add_column(campo, listCampos2)
                            registro_aux.append(aux)
                registro=self.metodo_sis(registro_aux)
                encabezados=auxEncabezados
            else:
                salidaTabla.field_names = encabezados
                if len(registro) > 0:
                    salidaTabla.add_rows(registro)

            if self.distinto != None:
                salidaTabla.clear()
                mostrar = []
                aux1 = registro
                for n in registro:
                    if self.metodo_Pegre(n, aux1) == 1:
                        mostrar.append(n)
                        print(n)
                    else:
                        cont = 0
                        for reco in mostrar:

                            if n == reco:
                                cont = 2
                                break
                            else:
                                cont =1

                        if cont == 1:
                            mostrar.append(n)
                registro=mostrar
                salidaTabla.add_rows(mostrar)


            if imprimir==None :
                add_text('\n')
                add_text(salidaTabla)
                add_text('\n')

            return retorno(registro[0][0],encabezados,registro)
        except:
            add_text("E-22005 error in assignment: the query could not be made.\n")