예제 #1
0
def calcularUpdate(arbol, ts):
    global lstResultado
    global contador
    contador += 1

    print("--#Iniciando calcularSelect[" + str(contador) + "]" + "[\'\'\'" +
          str(arbol.etiqueta) + "]")

    if (arbol is not None and arbol.esHoja is not None
            and arbol.esHoja == 'N'):
        if (arbol.etiqueta == 'set_clause'):
            ts.operacion_actual = 'set_clause'

    if (arbol is not None and arbol.esHoja is not None
            and arbol.esHoja == 'S'):
        #estamos en el subarbol de tablas
        if (arbol.etiqueta == 'table_name_s'):
            ts.operacion_actual = TS.TIPO_SELECT_CAMPOS.TABLAS

    #************************************
    #             ARBOL CON UN SOLO HIJO (UNARIO)
    #************************************

    if len(arbol.hijos) == 1:
        id = inc()
        if (arbol.etiqueta == 'value_list1'):
            if (arbol.hijos[0].etiqueta == 'func_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarValoresInsert(expCampo)
            elif (arbol.hijos[0].etiqueta == 'func_MD5'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.MD5.name),
                    str(arbol.hijos[0].hijos[0].lexema),
                    str(arbol.hijos[0].hijos[1].lexema), None, None, None)
                ts.agregarValoresInsert(expCampo)
            elif (arbol.hijos[0].etiqueta == 'value_list'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarValoresInsert(expCampo)

            else:
                calcularUpdate(arbol.hijos[0], ts)

        elif (arbol.etiqueta == 'insert_column_list1'):
            if (arbol.hijos[0].etiqueta == 'column_name'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCamposInsert(expCampo)

            else:
                calcularUpdate(arbol.hijos[0], ts)
        else:
            calcularUpdate(arbol.hijos[0], ts)

        #************************************
        #             ARBOL CON 2 HIJOS (BINARIO)
        #************************************
    elif len(arbol.hijos) == 2:
        id = inc()
        if (arbol.etiqueta == 'set_clause'):

            if (arbol.hijos[0].etiqueta == 'column_name'):
                if (arbol.hijos[0].esHoja == 'S'):
                    temporal1 = str(arbol.hijos[0].lexema)
                    #ts.agregarTablaInsert(temporal)
                else:
                    calcularUpdate(arbol.hijos[0], ts)
                    temporal1 = ts.valor_temporal
            elif (arbol.hijos[0].etiqueta == 'function_tipo_TRUE'):
                if (arbol.hijos[0].esHoja == 'S'):
                    temporal1 = str(arbol.hijos[0].lexema)
                    #ts.agregarTablaInsert(temporal)
                else:
                    calcularUpdate(arbol.hijos[0], ts)
                    temporal1 = ts.valor_temporal

            if (arbol.hijos[1].etiqueta == 'function_tipo_ENTERO'):
                if (arbol.hijos[1].esHoja == 'S'):
                    temporal2 = str(arbol.hijos[1].lexema)
                    #ts.agregarTablaInsert(temporal)
                else:
                    calcularUpdate(arbol.hijos[1], ts)
                    temporal2 = ts.valor_temporal

            elif (arbol.hijos[1].etiqueta == 'function_tipo_TRUE'):
                if (arbol.hijos[1].esHoja == 'S'):
                    temporal2 = str(arbol.hijos[1].lexema)
                    #ts.agregarTablaInsert(temporal)
                else:
                    calcularUpdate(arbol.hijos[1], ts)
                    temporal2 = ts.valor_temporal

            elif (arbol.hijos[1].etiqueta == 'function_tipo_FALSE'):
                if (arbol.hijos[1].esHoja == 'S'):
                    temporal2 = str(arbol.hijos[1].lexema)
                    #ts.agregarTablaInsert(temporal)
                else:
                    calcularUpdate(arbol.hijos[1], ts)
                    temporal2 = ts.valor_temporal

            if (arbol.hijos[1].etiqueta == 'column_func_name_select'):
                if (arbol.hijos[1].esHoja == 'S'):
                    temporal2 = str(arbol.hijos[1].lexema)
                    #ts.agregarTablaInsert(temporal)
                else:
                    calcularUpdate(arbol.hijos[1], ts)
                    temporal2 = ts.valor_temporal
                expCampo = TS.ExpresionCampo("set", temporal1, '=',
                                             temporal2.expresion1,
                                             temporal2.expresion2, None)
                ts.agregarCampoUpdate(expCampo)
                return 1

            expCampo = TS.ExpresionCampo("set", temporal1, '=', temporal2,
                                         None, None)
            ts.agregarCampoUpdate(expCampo)

        elif (arbol.etiqueta == 'value_list1'):

            if (arbol.hijos[0].etiqueta == 'value_list'):
                ts.agregarValoresInsert(arbol.hijos[0].lexema)
            elif (arbol.hijos[0].etiqueta == 'func_MD5'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.MD5.name),
                    str(arbol.hijos[0].hijos[0].lexema),
                    str(arbol.hijos[0].hijos[1].lexema), None, None, None)
                ts.agregaagregarValoresInsertrCampoInsert(expCampo)
            elif (arbol.hijos[0].etiqueta == 'func_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarValoresInsert(expCampo)
            else:
                calcularUpdate(arbol.hijos[0], ts)

            if (arbol.hijos[1].etiqueta == 'value_list'):
                ts.agregarValoresInsert(arbol.hijos[1].lexema)
            elif (arbol.hijos[1].etiqueta == 'func_MD5'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.MD5.name),
                    str(arbol.hijos[1].hijos[0].lexema),
                    str(arbol.hijos[1].hijos[1].lexema), None, None, None)
                ts.agregarValoresInsert(expCampo)
            elif (arbol.hijos[1].etiqueta == 'func_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarValoresInsert(expCampo)
            else:
                calcularUpdate(arbol.hijos[1], ts)

        elif (arbol.etiqueta == 'insert_column_list1'):

            if (arbol.hijos[0].etiqueta == 'column_name'):
                ts.agregarCamposInsert(arbol.hijos[0].lexema)
            else:
                calcularUpdate(arbol.hijos[0], ts)

            if (arbol.hijos[1].etiqueta == 'column_name'):
                ts.agregarCamposInsert(arbol.hijos[1].lexema)
            else:
                calcularUpdate(arbol.hijos[1], ts)

        elif (arbol.etiqueta == 'column_func_name_select'):

            if (arbol.hijos[0].etiqueta == 'function_tipo_SIN'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.SIN.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_COS'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.COS.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_SIND'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.SIND.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_TAN'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.TAN.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_TAND'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.TAND.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_ABS'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ABS.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CBRT'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.CBRT.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CEIL'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.CEIL.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CEILING'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CEILING.name),
                    str(arbol.hijos[0].lexema), str(arbol.hijos[1].lexema),
                    None, None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_DEGREES'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.DEGREES.name),
                    str(arbol.hijos[0].lexema), str(arbol.hijos[1].lexema),
                    None, None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_DIV'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.DIV.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_EXP'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.EXP.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_factorial'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.FACTORIAL.name),
                    str(arbol.hijos[0].lexema), str(arbol.hijos[1].lexema),
                    None, None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_FLOOR'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.FLOOR.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1
            elif (arbol.hijos[0].etiqueta == 'function_tipo_gcd'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.GCD.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_LN'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.LN.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_LOG'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.LOG.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_MOD'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.MOD.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_PI'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.PI.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_POWER'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.POWER.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_RADIANS'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.RADIANS.name),
                    str(arbol.hijos[0].lexema), str(arbol.hijos[1].lexema),
                    None, None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ROUND'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ROUND.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_SIGN'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.SIGN.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_SQRT'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.SQRT.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_TRUNC'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.TRUNC.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_RANDOM'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.RANDOM.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ACOS'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ACOS.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ASIN'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ASIN.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ASIND'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ASIND.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ATAN'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ATAN.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ATAND'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ATAND.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ATAN2'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ATAN2.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ATAN2D'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ATAN2D.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_COSD'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.COSD.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_COT'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.COT.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_COTd'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.COTD.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_sinh'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.SINH.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_COSH'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.COSH.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_TANH'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.TANH.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_asinh'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ASINH.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ACOSH'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ACOSH.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            elif (arbol.hijos[0].etiqueta == 'function_tipo_ATANH'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ATANH.name),
                                             str(arbol.hijos[0].lexema),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None)
                ts.valor_temporal = expCampo
                return 1

            # if(arbol.hijos[0].etiqueta == 'column_name'):
            #     ts.agregarCamposInsert(arbol.hijos[0].lexema)
            # else:
            #     calcularUpdate(arbol.hijos[0],ts)

            # if(arbol.hijos[1].etiqueta == 'column_name'):
            #     ts.agregarCamposInsert(arbol.hijos[1].lexema)
            # else:
            #     calcularUpdate(arbol.hijos[1],ts)

        else:
            valorRetorno1 = str(calcularUpdate(arbol.hijos[0], ts))
            valorRetorno2 = str(calcularUpdate(arbol.hijos[1], ts))
        return id

    elif len(arbol.hijos) == 3:
        id = inc()
        if (arbol.hijos[0].etiqueta == 'table_name'):
            if (arbol.hijos[0].esHoja == 'S'):
                temporal = str(arbol.hijos[0].lexema)
                ts.agregarTablaInsert(temporal)
            else:
                calcularUpdate(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

        elif (arbol.hijos[0].etiqueta == 'set_clause'):
            if (arbol.hijos[0].esHoja == 'S'):
                temporal = str(arbol.hijos[0].lexema)
                ts.agregarCampoSelect(temporal)
            else:
                calcularUpdate(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

        if (arbol.hijos[0].etiqueta == 'set_clause_list'):
            if (arbol.hijos[0].esHoja == 'S'):
                temporal = str(arbol.hijos[0].lexema)
                ts.agregarTablaInsert(temporal)
            else:
                calcularUpdate(arbol.hijos[1], ts)
                temporal1 = ts.valor_temporal

        elif (arbol.hijos[0].etiqueta == 'WHERE_CONDITION'):
            selectwhere.calcularSelectWhere(arbol.hijos[0], ts)

        if (arbol.hijos[1].etiqueta == 'table_name'):
            if (arbol.hijos[1].esHoja == 'S'):
                temporal = str(arbol.hijos[1].lexema)
                ts.agregarTablaInsert(temporal)
            else:
                calcularUpdate(arbol.hijos[1], ts)
                temporal1 = ts.valor_temporal

        elif (arbol.hijos[1].etiqueta == 'set_clause'):
            if (arbol.hijos[1].esHoja == 'S'):
                temporal = str(arbol.hijos[1].lexema)
                ts.agregarCampoSelect(temporal)
            else:
                calcularUpdate(arbol.hijos[1], ts)
                #temporal1 = ts.valor_temporal

        if (arbol.hijos[1].etiqueta == 'set_clause_list'):
            if (arbol.hijos[1].esHoja == 'S'):
                temporal = str(arbol.hijos[1].lexema)
                ts.agregarTablaInsert(temporal)
            else:
                calcularUpdate(arbol.hijos[1], ts)
                temporal1 = ts.valor_temporal

        elif (arbol.hijos[1].etiqueta == 'WHERE_CONDITION'):
            selectwhere.calcularSelectWhere(arbol.hijos[1], ts)

        if (arbol.hijos[2].etiqueta == 'table_name'):
            selectcampos.calcularSelectCampos(arbol.hijos[2], ts)

        elif (arbol.hijos[2].etiqueta == 'set_clause'):
            if (arbol.hijos[2].esHoja == 'S'):
                temporal = str(arbol.hijos[2].lexema)
                ts.agregarCampoSelect(temporal)
            else:
                calcularUpdate(arbol.hijos[2], ts)
                temporal1 = ts.valor_temporal

        if (arbol.hijos[2].etiqueta == 'set_clause_list'):
            if (arbol.hijos[2].esHoja == 'S'):
                temporal = str(arbol.hijos[2].lexema)
                ts.agregarTablaInsert(temporal)
            else:
                calcularUpdate(arbol.hijos[2], ts)
                temporal1 = ts.valor_temporal

        elif (arbol.hijos[2].etiqueta == 'WHERE_CONDITION'):
            selectwhere.calcularSelectWhere(arbol.hijos[2], ts)

        return id
예제 #2
0
def calcularSelectWhere(arbol, ts):
    global lstResultado
    global contador
    contador += 1

    print("--#Iniciando calcular[" + str(contador) + "]" + "[\'\'\'" +
          str(arbol.etiqueta) + "]")
    if arbol.esHoja == 'S':
        if len(arbol.hijos) == 1:
            id = inc()

            simbolo = TS.Simbolo(str(arbol.etiqueta), TS.TIPO_DATO.ETIQUETA,
                                 str(arbol.lexema))
            ts.agregar(simbolo)

            #********************* HOJAS PARA UNA SENTENCIA SELECT **************
            if (ts.tipo_operacion == TS.TIPO_OPERACION.SELECT):

                #estamos en una hoja de la seccion campos, almacenamos en lista campos
                if (ts.operacion_actual == TS.TIPO_SELECT.CAMPOS):
                    if (arbol.etiqueta == 'column_name_func'
                            or arbol.etiqueta == 'select_function_element'):
                        ts.valor_temporal = TS.ValorTemporal(
                            str(arbol.lexema), str(arbol.etiqueta))

                    #se comento ya que daba error en lista de id...
                    # elif(arbol.etiqueta == 'column_name_id' or arbol.etiqueta == 'value_expression') :
                    #     ts.valor_temporal = TS.ValorTemporal(str(arbol.lexema), str(arbol.etiqueta))
                    elif (arbol.etiqueta == 'column_name_opmult'):
                        ts.valor_temporal = TS.ValorTemporal(
                            str(arbol.lexema), str(arbol.etiqueta))
                        expCampo = TS.ExpresionCampo(
                            str(TS.CAMPO_FUNCION.SELECT_ASTERISCO.name),
                            str(arbol.lexema), None, None, None, None)
                        ts.agregarCampoSelect(expCampo)

                    elif (arbol.etiqueta == 'column_name_now'):
                        ts.valor_temporal = TS.ValorTemporal(
                            str(arbol.lexema), str(arbol.etiqueta))
                        expCampo = TS.ExpresionCampo(
                            str(TS.CAMPO_FUNCION.NOW.name), str(arbol.lexema),
                            None, None, None, None)
                        ts.agregarCampoSelect(expCampo)

                    elif (arbol.etiqueta == 'column_name_current_date'):
                        ts.valor_temporal = TS.ValorTemporal(
                            str(arbol.lexema), str(arbol.etiqueta))
                        expCampo = TS.ExpresionCampo(
                            str(TS.CAMPO_FUNCION.CURRENT_DATE.name),
                            str(arbol.lexema), None, None, None, None)
                        ts.agregarCampoSelect(expCampo)

                    elif (arbol.etiqueta == 'column_name_current_time'):
                        ts.valor_temporal = TS.ValorTemporal(
                            str(arbol.lexema), str(arbol.etiqueta))
                        expCampo = TS.ExpresionCampo(
                            str(TS.CAMPO_FUNCION.CURRENT_TIME.name),
                            str(arbol.lexema), None, None, None, None)
                        ts.agregarCampoSelect(expCampo)

                    elif (arbol.etiqueta == 'column_name_random'):
                        ts.valor_temporal = TS.ValorTemporal(
                            str(arbol.lexema), str(arbol.etiqueta))
                        expCampo = TS.ExpresionCampo(
                            str(TS.CAMPO_FUNCION.RANDOM.name),
                            str(arbol.lexema), None, None, None, None)
                        ts.agregarCampoSelect(expCampo)

                    else:
                        expCampo = TS.ExpresionCampo(
                            str(TS.CAMPO_FUNCION.ID.name), str(arbol.lexema),
                            None, None, None, None)
                        ts.agregarCampoSelect(expCampo)
                        #ts.agregarCampoSelect(str(arbol.lexema))

                #estamos en una hoja de la sección tablas, alamcenamos en lista tablas
                elif (ts.operacion_actual == TS.TIPO_SELECT.TABLAS):
                    ts.agregarTablaSelect(str(arbol.lexema))

                #estamos en una hoja de la sección condicion, enviamos como temporal el valor
                elif (ts.operacion_actual == TS.TIPO_SELECT.CONDICION):
                    ts.valor_temporal = TS.ValorTemporal(
                        str(arbol.lexema), str(arbol.etiqueta))

                #estamos en una hoja de la seccion grupo, almacenamos en lista grupo
                elif (ts.operacion_actual == TS.TIPO_SELECT.GRUPO):
                    ts.agregarGrupoSelect(str(arbol.lexema))
            return id
        elif len(arbol.hijos) > 1:
            id = inc()
            if len(arbol.hijos) == 3:
                if (ts.tipo_operacion == TS.TIPO_OPERACION.SELECT
                        and ts.operacion_actual == TS.TIPO_SELECT.CONDICION):
                    if (arbol.etiqueta == 'like_percent_predicate'):
                        ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.IN
                        expComparacion = TS.ExpresionListaComparadores(
                            str(arbol.hijos[0]), str(arbol.hijos[1]),
                            str(arbol.hijos[2]))
                        ts.agregarCondicionSelect(expComparacion)
            else:
                for x in range(0, len(arbol.hijos)):
                    pass
                    # dot.edge(str(id),'#'+str(id)+'[' +str(arbol.hijos[x])+']')
                return id

    #region
    elif len(arbol.hijos) == 1:
        id = inc()
        #arbol.hijos[0].etiquetaPadre = arbol.etiqueta
        if (arbol.etiqueta == 'in_value_list'):
            if (arbol.hijos[0].esHoja == 'S'):
                ts.valor_temporal = arbol.hijos[0].lexema
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal
        else:
            valorRetorno = str(calcularSelectWhere(arbol.hijos[0], ts))

        if (arbol.etiqueta == 'WHERE_CONDITION'):
            if (hasattr(ts, 'TIPO_SELECT_CONDICION')
                    and ts.TIPO_SELECT_CONDICION
                    == TS.TIPO_SELECT_CONDICION.COMPARACION):
                if (len(ts.lstcondiciones) == 0):
                    ts.agregarCondicionSelect(ts.valor_temporal)
            else:
                #se utiliza pruebas
                ts.agregarCondicionSelect(ts.valor_temporal)
        return id

    elif len(arbol.hijos) == 2:
        id = inc()
        if (arbol.etiqueta == 'in_value_list'):

            # str(calcularSelectWhere(arbol.hijos[0],ts))
            # temporal1 = ts.valor_temporal.valor
            if (arbol.hijos[0].esHoja == 'S'):
                temporal1 = str(arbol.hijos[0].lexema)
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[1],ts))
            # temporal2 = ts.valor_temporal.valor
            if (arbol.hijos[1].esHoja == 'S'):
                temporal2 = str(arbol.hijos[1].lexema)
            else:
                calcularSelectWhere(arbol.hijos[1], ts)
                temporal2 = ts.valor_temporal

            ts.valor_temporal = temporal1 + ',' + temporal2
        else:
            valorRetorno1 = str(calcularSelectWhere(arbol.hijos[0], ts))
            valorRetorno2 = str(calcularSelectWhere(arbol.hijos[1], ts))

    elif len(arbol.hijos) == 3:
        id = inc()

        if (arbol.etiqueta == 'comparison_predicate'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.COMPARACION

            #se valida si se puede obtener directamente la hoja o hay que sintetizar
            # str(calcularSelectWhere(arbol.hijos[0],ts))
            # temporal1 = ts.valor_temporal.valor
            if (arbol.hijos[0].etiqueta == 'value_expression'):
                temporal1 = arbol.hijos[0].lexema
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal.valor

            if (arbol.hijos[1].etiqueta == 'comp_op'):
                temporal2 = arbol.hijos[1].lexema
            else:
                calcularSelectWhere(arbol.hijos[1], ts)
                temporal2 = ts.valor_temporal.valor

            if (arbol.hijos[2].etiqueta == 'value_expression'):
                temporal3 = arbol.hijos[2].lexema
            elif (arbol.hijos[2].etiqueta == 'fun_now'):
                temporal3 = 'now'
            else:
                calcularSelectWhere(arbol.hijos[2], ts)
                temporal3 = ts.valor_temporal.valor

            #se almacena como un temporal porque probablemente existan mas item como lista
            #valTemp = TS.ExpresionComparacion(temporal1,temporal2,temporal3,None,TS.TIPO_SELECT_CONDICION.COMPARACION)
            #ts.valor_temporal.valor = TS.ValorTemporal(valTemp, None)
            #expIn = TS.ExpresionComparacion(temporal1,temporal2,temporal3,None,TS.TIPO_SELECT_CONDICION.IN)
            # ts.agregarCondicionSelect(expIn)
            #ts.agregarCondicionSelect(expComparacion)
            valTemp = TS.ExpresionComparacion(
                temporal1, temporal2, temporal3, None,
                TS.TIPO_SELECT_CONDICION.COMPARACION)
            ts.valor_temporal = TS.ValorTemporal(valTemp, None)

        elif (arbol.etiqueta == 'search_condition'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.COMPARACION

            # valorRetorno1 = str(calcularSelectWhere(arbol.hijos[0],ts))
            # temporal1 = ts.valor_temporal.valor
            if (arbol.hijos[0].esHoja == 'S'):
                if (arbol.hijos[0].etiqueta == 'like_percent_predicate'):
                    ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.IN
                    expComparacion = TS.ExpresionListaComparadores(
                        str(arbol.hijos[0].hijos[0]),
                        str(arbol.hijos[0].hijos[1]),
                        str(arbol.hijos[0].hijos[2]))
                    ts.agregarCondicionSelect(expComparacion)
                    temporal1 = ts.valor_temporal
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

            #valorRetorno2 = str(calcularSelectWhere(arbol.hijos[1],ts))
            #temporal2 = arbol.hijos[1].lexema
            if (arbol.hijos[1].esHoja == 'S'):
                temporal2 = arbol.hijos[1].lexema
            else:
                calcularSelectWhere(arbol.hijos[1], ts)
                temporal2 = ts.valor_temporal

            # valorRetorno3 = str(calcularSelectWhere(arbol.hijos[2],ts))
            # temporal3 = ts.valor_temporal.valor
            if (arbol.hijos[2].esHoja == 'S'):
                temporal3 = arbol.hijos[2].lexema
            else:
                calcularSelectWhere(arbol.hijos[2], ts)
                temporal3 = ts.valor_temporal

            #Como es item unico se envía directamente a la lista de comparación
            #expComparacion = TS.ExpresionListaComparadores(temporal1,temporal2,temporal3)
            expComparacion = TS.ExpresionListaComparadores(
                temporal1, temporal2, temporal3)
            #ts.valor_temporal.valor = TS.ValorTemporal(valTemp, None)

            ts.agregarCondicionSelect(expComparacion)
        elif (arbol.etiqueta == 'boolean_term'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.COMPARACION

            # valorRetorno1 = str(calcularSelectWhere(arbol.hijos[0],ts))
            # temporal1 = ts.valor_temporal.valor
            if (arbol.hijos[0].esHoja == 'S'):
                temporal1 = arbol.hijos[0].lexema
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

            # valorRetorno2 = str(calcularSelectWhere(arbol.hijos[1],ts))
            # temporal2 = ts.valor_temporal.valor
            if (arbol.hijos[1].etiqueta == 'opAnd'
                ):  # or arbol.hijos[1].etiqueta == 'opOr'):
                temporal2 = arbol.hijos[1].lexema
            else:
                calcularSelectWhere(arbol.hijos[1], ts)
                temporal2 = ts.valor_temporal.valor

            # valorRetorno3 = str(calcularSelectWhere(arbol.hijos[2],ts))
            # temporal3 = ts.valor_temporal.valor
            if (arbol.hijos[2].esHoja == 'S'):
                temporal3 = arbol.hijos[2].lexema
            else:
                calcularSelectWhere(arbol.hijos[2], ts)
                temporal3 = ts.valor_temporal

            expComparacion = TS.ExpresionComparacion(
                temporal1, temporal2, temporal3, None,
                TS.TIPO_SELECT_CONDICION.COMPARACION)

            ts.valor_temporal = expComparacion

        elif (arbol.etiqueta == 'in_predicate'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.IN

            # str(calcularSelectWhere(arbol.hijos[0],ts))
            # temporal1 = ts.valor_temporal.valor
            if (arbol.hijos[0].esHoja == 'S'):
                temporal1 = arbol.hijos[0].lexema
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

            if (arbol.hijos[1].etiqueta == 'predicatein'):
                temporal2 = arbol.hijos[1].lexema
            else:
                calcularSelectWhere(arbol.hijos[1], ts)
                temporal2 = ts.valor_temporal.valor

            # str(calcularSelectWhere(arbol.hijos[2],ts))
            # temporal3 = ts.valor_temporal.valor
            if (arbol.hijos[2].esHoja == 'S'):
                temporal3 = arbol.hijos[2].lexema
            else:
                calcularSelectWhere(arbol.hijos[2], ts)
                temporal3 = ts.valor_temporal

            expIn = TS.ExpresionComparacion(temporal1, temporal2, temporal3,
                                            None, TS.TIPO_SELECT_CONDICION.IN)
            ts.agregarCondicionSelect(expIn)
        # elif(arbol.etiqueta == 'null_predicate'):
        #     ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.NULL

        #     str(calcularSelectWhere(arbol.hijos[0],ts))
        #     temporal1 = ts.valor_temporal.valor

        #     str(calcularSelectWhere(arbol.hijos[1],ts))
        #     temporal2 = ts.valor_temporal.valor

        #     str(calcularSelectWhere(arbol.hijos[2],ts))
        #     temporal3 = ts.valor_temporal.valor

        # expIn = TS.ExpresionComparacion(temporal1,temporal2,temporal3,None,TS.TIPO_SELECT_CONDICION.NULL)
        # ts.agregarCondicionSelect(expIn)
        elif (arbol.etiqueta == 'like_percent_predicate'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.LIKE

            #str(calcularSelectWhere(arbol.hijos[0],ts))
            temporal1 = arbol.hijos[0]

            #str(calcularSelectWhere(arbol.hijos[1],ts))
            temporal2 = arbol.hijos[1]

            #str(calcularSelectWhere(arbol.hijos[2],ts))
            temporal3 = arbol.hijos[2]

            expIn = TS.ExpresionComparacion(temporal1, temporal2, temporal3,
                                            None,
                                            TS.TIPO_SELECT_CONDICION.LIKE)
            ts.agregarCondicionSelect(expIn)
        elif (arbol.etiqueta == 'column_reference'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.SUBSTRING

            temporal1 = arbol.hijos[0].lexema
            temporal2 = arbol.hijos[1].lexema
            temporal3 = arbol.hijos[2].lexema

            # str(calcularSelectWhere(arbol.hijos[3],ts))
            # temporal4 = ts.valor_temporal.valor

            #se almacena como un temporal porque probablemente existan mas item como lista
            ts.valor_temporal = TS.ExpresionComparacion(
                temporal1, temporal2, temporal3, None,
                TS.TIPO_SELECT_CONDICION.SUBSTRING)
        else:
            valorRetorno1 = str(calcularSelectWhere(arbol.hijos[0], ts))
            valorRetorno2 = str(calcularSelectWhere(arbol.hijos[1], ts))
            valorRetorno3 = str(calcularSelectWhere(arbol.hijos[2], ts))
        return id

        #************************************
        #             ARBOL CON 4 HIJOS
        #************************************

    elif len(arbol.hijos) == 4:
        id = inc()

        if (arbol.etiqueta == 'null_predicate'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.NOT_NULL

            # str(calcularSelectWhere(arbol.hijos[0],ts))
            # temporal1 = ts.valor_temporal.valor
            if (arbol.hijos[0].esHoja == 'S'):
                temporal1 = arbol.hijos[0].lexema
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[1],ts))
            # temporal2 = ts.valor_temporal.valor
            if (arbol.hijos[1].esHoja == 'S'):
                temporal2 = arbol.hijos[1].lexema
            else:
                calcularSelectWhere(arbol.hijos[1], ts)
                temporal2 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[2],ts))
            # temporal3 = ts.valor_temporal.valor
            if (arbol.hijos[2].esHoja == 'S'):
                temporal3 = arbol.hijos[2].lexema
            else:
                calcularSelectWhere(arbol.hijos[2], ts)
                temporal3 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[3],ts))
            # temporal4 = ts.valor_temporal.valor
            if (arbol.hijos[3].esHoja == 'S'):
                temporal4 = arbol.hijos[3].lexema
            else:
                calcularSelectWhere(arbol.hijos[3], ts)
                temporal4 = ts.valor_temporal

            expIn = TS.ExpresionComparacion(temporal1, temporal2, temporal3,
                                            temporal4,
                                            TS.TIPO_SELECT_CONDICION.NOT_NULL)
            ts.agregarCondicionSelect(expIn)
        elif (arbol.etiqueta == 'substring_predicate'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.SUBSTRING

            if (arbol.hijos[0].esHoja == 'S'):
                temporal1 = arbol.hijos[0].lexema
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[1],ts))
            # temporal2 = ts.valor_temporal
            if (arbol.hijos[1].esHoja == 'S'):
                temporal2 = arbol.hijos[1].lexema
            else:
                calcularSelectWhere(arbol.hijos[1], ts)
                temporal2 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[2],ts))
            # temporal3 = ts.valor_temporal
            if (arbol.hijos[2].esHoja == 'S'):
                temporal3 = arbol.hijos[2].lexema
            else:
                calcularSelectWhere(arbol.hijos[2], ts)
                temporal3 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[3],ts))
            # temporal4 = ts.valor_temporal
            if (arbol.hijos[3].esHoja == 'S'):
                temporal4 = arbol.hijos[3].lexema
            else:
                calcularSelectWhere(arbol.hijos[3], ts)
                temporal4 = ts.valor_temporal

            expIn = TS.ExpresionComparacion(temporal1, temporal2, temporal3,
                                            temporal4,
                                            TS.TIPO_SELECT_CONDICION.SUBSTRING)
            ts.agregarCondicionSelect(expIn)
        else:
            valorRetorno1 = str(calcularSelectWhere(arbol.hijos[0], ts))
            valorRetorno2 = str(calcularSelectWhere(arbol.hijos[1], ts))
            valorRetorno3 = str(calcularSelectWhere(arbol.hijos[2], ts))
            valorRetorno4 = str(calcularSelectWhere(arbol.hijos[3], ts))

        return id

        #************************************
        #             ARBOL CON 5 HIJOS
        #************************************

    elif len(arbol.hijos) == 5:
        id = inc()

        #region
        if (arbol.etiqueta == 'between_predicate'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.BETWEEN
            temporal1 = arbol.hijos[0].lexema
            temporal2 = arbol.hijos[1].lexema
            temporal3 = arbol.hijos[2].lexema
            temporal4 = arbol.hijos[3].lexema
            temporal5 = arbol.hijos[4].lexema

            expComparacion = TS.ExpresionComparacion(
                temporal3, temporal1, temporal5, None,
                TS.TIPO_SELECT_CONDICION.BETWEEN)
            #ts.agregarCondicionSelect(expComparacion)
            #valTemp = TS.ExpresionComparacion(temporal1, None, None,None,TS.TIPO_SELECT_CONDICION.COMPARACION)
            ts.valor_temporal = TS.ValorTemporal(expComparacion, None)
        elif (arbol.etiqueta == 'distinct_predicate'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.DISTINCT
            temporal1 = arbol.hijos[0].lexema
            temporal2 = arbol.hijos[1].lexema
            temporal3 = arbol.hijos[2].lexema
            temporal4 = arbol.hijos[3].lexema
            temporal5 = arbol.hijos[4].lexema

            expComparacion = TS.ExpresionComparacion(
                temporal3, temporal1, temporal5, None,
                TS.TIPO_SELECT_CONDICION.DISTINCT)
            ts.agregarCondicionSelect(expComparacion)
        #endregion
        else:
            valorRetorno1 = str(calcularSelectWhere(arbol.hijos[0], ts))
            valorRetorno2 = str(calcularSelectWhere(arbol.hijos[1], ts))
            valorRetorno3 = str(calcularSelectWhere(arbol.hijos[2], ts))
            valorRetorno4 = str(calcularSelectWhere(arbol.hijos[3], ts))
            valorRetorno5 = str(calcularSelectWhere(arbol.hijos[4], ts))

        return id

        #************************************
        #             ARBOL CON 6 HIJOS
        #************************************

    elif len(arbol.hijos) == 6:
        id = inc()
        #region
        if (arbol.etiqueta == 'between_predicate'):
            ts.TIPO_SELECT_CONDICION = TS.TIPO_SELECT_CONDICION.NOT_BETWEEN

            # str(calcularSelectWhere(arbol.hijos[0],ts))
            # temporal1 = ts.valor_temporal.valor
            if (arbol.hijos[0].esHoja == 'S'):
                temporal1 = arbol.hijos[0].lexema
            else:
                calcularSelectWhere(arbol.hijos[0], ts)
                temporal1 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[1],ts))
            # temporal2 = ts.valor_temporal.valor
            if (arbol.hijos[1].esHoja == 'S'):
                temporal2 = arbol.hijos[1].lexema
            else:
                calcularSelectWhere(arbol.hijos[1], ts)
                temporal2 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[2],ts))
            # temporal3 = ts.valor_temporal.valor
            if (arbol.hijos[2].esHoja == 'S'):
                temporal3 = arbol.hijos[2].lexema
            else:
                calcularSelectWhere(arbol.hijos[2], ts)
                temporal3 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[3],ts))
            # temporal4 = ts.valor_temporal.valor
            if (arbol.hijos[3].esHoja == 'S'):
                temporal4 = arbol.hijos[3].lexema
            else:
                calcularSelectWhere(arbol.hijos[3], ts)
                temporal4 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[4],ts))
            # temporal5 = ts.valor_temporal.valor
            if (arbol.hijos[4].esHoja == 'S'):
                temporal5 = arbol.hijos[4].lexema
            else:
                calcularSelectWhere(arbol.hijos[4], ts)
                temporal5 = ts.valor_temporal

            # str(calcularSelectWhere(arbol.hijos[5],ts))
            # temporal6 = ts.valor_temporal.valor
            if (arbol.hijos[5].esHoja == 'S'):
                temporal6 = arbol.hijos[5].lexema
            else:
                calcularSelectWhere(arbol.hijos[5], ts)
                temporal6 = ts.valor_temporal

            expComparacion = TS.ExpresionComparacion(
                temporal4, temporal1, temporal6, None,
                TS.TIPO_SELECT_CONDICION.NOT_BETWEEN)
            ts.agregarCondicionSelect(expComparacion)
        #endregion
        else:
            valorRetorno1 = str(calcularSelectWhere(arbol.hijos[0], ts))
            valorRetorno2 = str(calcularSelectWhere(arbol.hijos[1], ts))
            valorRetorno3 = str(calcularSelectWhere(arbol.hijos[2], ts))
            valorRetorno4 = str(calcularSelectWhere(arbol.hijos[3], ts))
            valorRetorno5 = str(calcularSelectWhere(arbol.hijos[4], ts))
            valorRetorno6 = str(calcularSelectWhere(arbol.hijos[5], ts))
예제 #3
0
def calcularUpdateSet(arbol, ts):
    global lstResultado
    global contador
    contador += 1

    print("--#Iniciando calcularSelect[" + str(contador) + "]" + "[\'\'\'" +
          str(arbol.etiqueta) + "]")

    if (arbol is not None and arbol.esHoja is not None
            and arbol.esHoja == 'N'):
        if (arbol.etiqueta == 'select_colum_list'):
            ts.operacion_actual = TS.TIPO_SELECT_CAMPOS.COLUMNAS

    if (arbol is not None and arbol.esHoja is not None
            and arbol.esHoja == 'S'):
        #estamos en el subarbol de tablas
        if (arbol.etiqueta == 'table_name_s'):
            ts.operacion_actual = TS.TIPO_SELECT_CAMPOS.TABLAS

    #************************************
    #             ARBOL CON UN SOLO HIJO (UNARIO)
    #************************************

    if len(arbol.hijos) == 1:
        id = inc()
        if (arbol.etiqueta == 'select_column_list'):
            if (arbol.hijos[0].etiqueta == 'function_tipo_ID'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CURRENT_DATE'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_DATE.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CURRENT_TIME'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_TIME.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_OPMULT'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.SELECT_ASTERISCO.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'DISTINCT_column_name_select'):
                expCampo = TS.ExpresionCampo(
                    str(TS.TIPO_SELECT_CONDICION.DISTINCT.name),
                    str(arbol.hijos[0].hijos[0].lexema), None, None, None,
                    None)
                ts.agregarCampoSelect(expCampo)
            else:
                calcularUpdateSet(arbol.hijos[0], ts)
        # elif(arbol.hijos[0].etiqueta == 'table_name_s'):
        #     ts.agregarTablaSelect(arbol.hijos[0].lexema)
        # if(arbol.etiqueta == 'column_func_name_select'):
        #     if(arbol.hijos[0].etiqueta == 'function_tipo_ID'):
        #         calcularUpdateSet(arbol.hijos[0],ts)
        return id

        #************************************
        #             ARBOL CON 2 HIJOS (BINARIO)
        #************************************
    elif len(arbol.hijos) == 2:
        id = inc()
        if (arbol.etiqueta == 'SELECT_FROM'):

            if (arbol.hijos[0].etiqueta == 'table_name_s'):
                ts.agregarTablaSelect(arbol.hijos[0].lexema)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_ID'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CURRENT_DATE'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_DATE.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CURRENT_TIME'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_TIME.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_OPMULT'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.SELECT_ASTERISCO.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'DISTINCT_column_name_select'):
                expCampo = TS.ExpresionCampo(
                    str(TS.TIPO_SELECT_CONDICION.DISTINCT.name),
                    str(arbol.hijos[0].hijos[0].lexema), None, None, None,
                    None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'column_name_func'):
                if (arbol.hijos[0].hijos[0].etiqueta
                        == 'select_function_element_ID'
                        and arbol.hijos[0].hijos[1].etiqueta
                        == 'column_select_punto'):
                    expCampo = TS.ExpresionCampo(
                        str(TS.CAMPO_FUNCION.SELECT_PUNTO.name),
                        str(arbol.hijos[0].hijos[0].lexema),
                        arbol.hijos[0].hijos[1].hijos[0].lexema, None, None,
                        None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_RANDOM'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.RANDOM.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)

            else:
                calcularUpdateSet(arbol.hijos[0], ts)

            if (arbol.hijos[1].etiqueta == 'table_name_s'):
                ts.agregarTablaSelect(arbol.hijos[1].lexema)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_ID'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID.name),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_CURRENT_DATE'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_DATE.name),
                    str(arbol.hijos[1].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_CURRENT_TIME'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_TIME.name),
                    str(arbol.hijos[1].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_OPMULT'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.SELECT_ASTERISCO.name),
                    str(arbol.hijos[1].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'DISTINCT_column_name_select'):
                expCampo = TS.ExpresionCampo(
                    str(TS.TIPO_SELECT_CONDICION.DISTINCT.name),
                    str(arbol.hijos[1].hijos[0].lexema), None, None, None,
                    None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'column_name_func'):
                if (arbol.hijos[1].hijos[0].etiqueta
                        == 'select_function_element_ID'
                        and arbol.hijos[1].hijos[1].etiqueta
                        == 'column_select_punto'):
                    expCampo = TS.ExpresionCampo(
                        str(TS.CAMPO_FUNCION.SELECT_PUNTO.name),
                        str(arbol.hijos[1].hijos[0].lexema),
                        arbol.hijos[1].hijos[1].hijos[0].lexema, None, None,
                        None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_RANDOM'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.RANDOM.name),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            else:
                calcularUpdateSet(arbol.hijos[1], ts)

        elif (arbol.etiqueta == 'select_column_list'):
            if (arbol.hijos[0].etiqueta == 'function_tipo_ID'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CURRENT_DATE'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_DATE.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_CURRENT_TIME'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_TIME.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_OPMULT'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.SELECT_ASTERISCO.name),
                    str(arbol.hijos[0].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'DISTINCT_column_name_select'):
                expCampo = TS.ExpresionCampo(
                    str(TS.TIPO_SELECT_CONDICION.DISTINCT.name),
                    str(arbol.hijos[0].hijos[0].lexema), None, None, None,
                    None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'column_name_func'):
                if (arbol.hijos[0].hijos[0].etiqueta
                        == 'select_function_element_ID'
                        and arbol.hijos[0].hijos[1].etiqueta
                        == 'column_select_punto'):
                    expCampo = TS.ExpresionCampo(
                        str(TS.CAMPO_FUNCION.SELECT_PUNTO.name),
                        str(arbol.hijos[0].hijos[0].lexema),
                        arbol.hijos[0].hijos[1].hijos[0].lexema, None, None,
                        None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[0].etiqueta == 'function_tipo_RANDOM'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.RANDOM.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            else:
                calcularUpdateSet(arbol.hijos[0], ts)

            if (arbol.hijos[1].etiqueta == 'function_tipo_ID'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID.name),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_CURRENT_DATE'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_DATE.name),
                    str(arbol.hijos[1].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_CURRENT_TIME'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.CURRENT_TIME.name),
                    str(arbol.hijos[1].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_OPMULT'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.SELECT_ASTERISCO.name),
                    str(arbol.hijos[1].lexema), None, None, None, None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'DISTINCT_column_name_select'):
                expCampo = TS.ExpresionCampo(
                    str(TS.TIPO_SELECT_CONDICION.DISTINCT.name),
                    str(arbol.hijos[1].hijos[0].lexema), None, None, None,
                    None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'column_name_func'):
                if (arbol.hijos[1].hijos[0].etiqueta
                        == 'select_function_element_ID'
                        and arbol.hijos[1].hijos[1].etiqueta
                        == 'column_select_punto'):
                    expCampo = TS.ExpresionCampo(
                        str(TS.CAMPO_FUNCION.SELECT_PUNTO.name),
                        str(arbol.hijos[1].hijos[0].lexema),
                        arbol.hijos[1].hijos[1].hijos[0].lexema, None, None,
                        None)
                ts.agregarCampoSelect(expCampo)
            elif (arbol.hijos[1].etiqueta == 'function_tipo_RANDOM'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.RANDOM.name),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)

            else:
                calcularUpdateSet(arbol.hijos[1], ts)

        elif (arbol.etiqueta == 'column_name_select_AS_value_expression'):
            expCampo = TS.ExpresionCampo('AS', str(arbol.hijos[0].lexema),
                                         str(arbol.hijos[1].lexema), None,
                                         None, None)
            ts.agregarCampoSelect(expCampo)

        elif (arbol.etiqueta == 'column_func_name_select'):
            if (arbol.hijos[0].etiqueta[14:] == 'EXTRACT'):
                if (arbol.hijos[1].etiqueta ==
                        'column_datefuntion_select_from_timestamp'):
                    tipoExpExtract = arbol.hijos[1].hijos[0].lexema
                    valorExpExtract = arbol.hijos[1].hijos[1].lexema
                    expCampo = TS.ExpresionCampo(
                        str(TS.CAMPO_FUNCION.EXTRACT.name), tipoExpExtract,
                        valorExpExtract, None, None, None)
                    ts.agregarCampoSelect(expCampo)
            else:
                expCampo = TS.ExpresionCampo(str(arbol.hijos[0].etiqueta[14:]),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarCampoSelect(expCampo)

        else:
            valorRetorno1 = str(calcularUpdateSet(arbol.hijos[0], ts))
            valorRetorno2 = str(calcularUpdateSet(arbol.hijos[1], ts))
        return id
예제 #4
0
def calcularInsertCampos(arbol, ts):
    global lstResultado
    global contador
    contador += 1

    print("--#Iniciando calcularSelect[" + str(contador) + "]" + "[\'\'\'" +
          str(arbol.etiqueta) + "]")

    if (arbol is not None and arbol.esHoja is not None
            and arbol.esHoja == 'N'):
        if (arbol.etiqueta == 'select_colum_list'):
            ts.operacion_actual = TS.TIPO_SELECT_CAMPOS.COLUMNAS

    if (arbol is not None and arbol.esHoja is not None
            and arbol.esHoja == 'S'):
        #estamos en el subarbol de tablas
        if (arbol.etiqueta == 'table_name_s'):
            ts.operacion_actual = TS.TIPO_SELECT_CAMPOS.TABLAS

    #************************************
    #             ARBOL CON UN SOLO HIJO (UNARIO)
    #************************************

    if len(arbol.hijos) == 1:
        id = inc()
        if (arbol.etiqueta == 'value_list1'):
            if (arbol.hijos[0].etiqueta == 'func_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarValoresInsert(expCampo)
            elif (arbol.hijos[0].etiqueta == 'func_MD5'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.MD5.name),
                    str(arbol.hijos[0].hijos[0].lexema),
                    str(arbol.hijos[0].hijos[1].lexema), None, None, None)
                ts.agregarValoresInsert(expCampo)
            elif (arbol.hijos[0].etiqueta == 'value_list'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarValoresInsert(expCampo)

            else:
                calcularInsertCampos(arbol.hijos[0], ts)

        elif (arbol.etiqueta == 'insert_column_list1'):
            if (arbol.hijos[0].etiqueta == 'column_name'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.ID),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarCamposInsert(expCampo)

            else:
                calcularInsertCampos(arbol.hijos[0], ts)
        else:
            calcularInsertCampos(arbol.hijos[0], ts)

        #************************************
        #             ARBOL CON 2 HIJOS (BINARIO)
        #************************************
    elif len(arbol.hijos) == 2:
        id = inc()
        if (arbol.etiqueta == 'insert_statement'):

            if (arbol.hijos[0].etiqueta == 'table_name'):
                if (arbol.hijos[0].esHoja == 'S'):
                    temporal = str(arbol.hijos[0].lexema)
                    ts.agregarTablaInsert(temporal)
                else:
                    calcularInsertCampos(arbol.hijos[0], ts)
                    temporal1 = ts.valor_temporal

            elif (arbol.hijos[0].etiqueta == 'insert_columns_and_source'):
                calcularInsertCampos(arbol.hijos[0], ts)
            else:
                calcularInsertCampos(arbol.hijos[0], ts)

            if (arbol.hijos[1].etiqueta == 'table_name'):
                if (arbol.hijos[1].esHoja == 'S'):
                    temporal = str(arbol.hijos[1].lexema)
                    ts.agregarTablaInsert(temporal)
                else:
                    calcularInsertCampos(arbol.hijos[1], ts)
                    temporal1 = ts.valor_temporal

            elif (arbol.hijos[1].etiqueta == 'insert_columns_and_source'):
                calcularInsertCampos(arbol.hijos[1], ts)
            else:
                calcularInsertCampos(arbol.hijos[1], ts)

        elif (arbol.etiqueta == 'value_list1'):

            if (arbol.hijos[0].etiqueta == 'value_list'):
                ts.agregarValoresInsert(arbol.hijos[0].lexema)
            elif (arbol.hijos[0].etiqueta == 'func_MD5'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.MD5.name),
                    str(arbol.hijos[0].hijos[0].lexema),
                    str(arbol.hijos[0].hijos[1].lexema), None, None, None)
                ts.agregaagregarValoresInsertrCampoInsert(expCampo)
            elif (arbol.hijos[0].etiqueta == 'func_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[0].lexema), None,
                                             None, None, None)
                ts.agregarValoresInsert(expCampo)
            else:
                calcularInsertCampos(arbol.hijos[0], ts)

            if (arbol.hijos[1].etiqueta == 'value_list'):
                ts.agregarValoresInsert(arbol.hijos[1].lexema)
            elif (arbol.hijos[1].etiqueta == 'func_MD5'):
                expCampo = TS.ExpresionCampo(
                    str(TS.CAMPO_FUNCION.MD5.name),
                    str(arbol.hijos[1].hijos[0].lexema),
                    str(arbol.hijos[1].hijos[1].lexema), None, None, None)
                ts.agregarValoresInsert(expCampo)
            elif (arbol.hijos[1].etiqueta == 'func_NOW'):
                expCampo = TS.ExpresionCampo(str(TS.CAMPO_FUNCION.NOW.name),
                                             str(arbol.hijos[1].lexema), None,
                                             None, None, None)
                ts.agregarValoresInsert(expCampo)
            else:
                calcularInsertCampos(arbol.hijos[1], ts)

        elif (arbol.etiqueta == 'insert_column_list1'):

            if (arbol.hijos[0].etiqueta == 'column_name'):
                ts.agregarCamposInsert(arbol.hijos[0].lexema)
            else:
                calcularInsertCampos(arbol.hijos[0], ts)

            if (arbol.hijos[1].etiqueta == 'column_name'):
                ts.agregarCamposInsert(arbol.hijos[1].lexema)
            else:
                calcularInsertCampos(arbol.hijos[1], ts)

        else:
            valorRetorno1 = str(calcularInsertCampos(arbol.hijos[0], ts))
            valorRetorno2 = str(calcularInsertCampos(arbol.hijos[1], ts))
        return id