Esempio n. 1
0
    def do_funcion(self, p_inst, p_st, p_es):
        key = 'CFUN_'+p_inst.id
        existe = p_st.get(key)
        parametros = ""
        declaraciones = ""

        if p_inst.parametros != None:
            for parametro in p_inst.parametros:
                parametros += parametro.id + ' Tipo: ' + str(parametro.tipo._instruccion) +'<br>'
            if not existe:
                if p_inst.declaraciones != None:
                    for declaracion in p_inst.declaraciones:
                        declaraciones += declaracion.id + ' Tipo: ' +declaracion.tipo + '<br>'
                    simbolo = st.Symbol(key, p_inst.id, 'FUNCTION',parametros,'',declaraciones)
                    p_st.add(simbolo)
                else:
                    simbolo = st.Symbol(key, p_inst.id, 'FUNCTION',parametros,'',p_inst.declaraciones)
                    p_st.add(simbolo)

        else:
            if not existe:
                if p_inst.declaraciones != None:
                    for declaracion in p_inst.declaraciones:
                        declaraciones += declaracion.id + ' Tipo: ' +declaracion.tipo + '<br>'
                    simbolo = st.Symbol(key, p_inst.id, 'FUNCTION',None,'',declaraciones)
                    p_st.add(simbolo)
                else:
                    simbolo = st.Symbol(key, p_inst.id, 'FUNCTION',None,'',p_inst.declaraciones)
                    p_st.add(simbolo)
Esempio n. 2
0
    def do_drop_tb(self, p_inst, p_st, p_es):
        valor2 = 0
        list = []
        listI = []
        for keys, value in p_st.symbols.items():
            if value.id == p_inst.nombre:
                BDD = value.value

        for keys, value in p_st.symbols.items():
            if value.type == 'use':
                valor2 = 1
                list.append(value.id)
        if valor2 == 0:
            error = es.errorSemantico(
                'DTB_' + p_inst.nombre,
                'No se ha seleccionado ninguna base de datos para crear la tabla '
                + p_inst.nombre)
            p_es.agregar(error)
            self.new_output(error.tipo)
        else:
            BDDU = list.pop()
            if BDDU == BDD:
                key = 'DTB_' + p_inst.nombre
                simbolo = st.Symbol(key, p_inst.nombre, 'drop table', BDD)
                p_st.add(simbolo)
                dropTable(BDD, p_inst.nombre)
                self.new_output("SE LA ELIMINADO LA TABLA \'" + p_inst.nombre +
                                "\' EN LA BASE DE DATOS \'" + BDD + "\'.")
            else:
                error = es.errorSemantico(
                    'DTB_' + p_inst.tabla,
                    'La tabla ' + p_inst.tabla + ' no existe')
                p_es.agregar(error)
                self.new_output(error.tipo)
Esempio n. 3
0
 def do_create_tb(self, p_inst, p_st, p_es, p_ct):
     key = 'CTB_' + p_inst.nombreTabla + '_'
     existe = p_st.get(key)
     if not existe:
         simbolo = st.Symbol(key, p_inst.nombreTabla, 'create table',
                             p_inst.atributos, '', '')
         p_st.add(simbolo)
Esempio n. 4
0
    def do_drop_tb(inst, p_inst, p_st, p_es):
        valor2 = 0
        list = []
        listI = []
        for keys, value in p_st.symbols.items():
            if value.id == p_inst.nombre:
                BDD = value.value

        for keys, value in p_st.symbols.items():
            if value.type == 'use':
                valor2 = 1
                list.append(value.id)
        if valor2 == 0:
            error = es.errorSemantico(
                'DTB_' + p_inst.nombre,
                'No se ha seleccionado ninguna base de datos para crear la tabla '
                + p_inst.nombre)
            p_es.agregar(error)
        else:
            BDDU = list.pop()
            if BDDU == BDD:
                key = 'DTB_' + p_inst.nombre
                simbolo = st.Symbol(key, p_inst.nombre, 'insert table', BDD)
                p_st.add(simbolo)
                dropTable(BDD, p_inst.nombre)

            else:
                error = es.errorSemantico(
                    'ITB_' + p_inst.tabla,
                    'La tabla ' + p_inst.tabla + ' no existe')
                p_es.agregar(error)
Esempio n. 5
0
    def do_create_tb(self, p_inst, p_st, p_es, p_ct):
        list = []
        valor = 0
        for keys, value in p_st.symbols.items():
            if value.type == 'use':
                valor = 1
                list.append(value.id)

        if valor == 0:
            error = es.errorSemantico(
                'CTB_' + p_inst.nombreTabla,
                'No se ha seleccionado ninguna base de datos para crear la tabla '
                + p_inst.nombreTabla)
            p_es.agregar(error)
            self.new_output(error.tipo)
        else:
            BDD = list.pop()
            cantCol = len(p_inst.atributos)
            nTB = p_inst.nombreTabla

        key = 'CTB_' + p_inst.nombreTabla + '_' + BDD

        existe = p_st.get(key)
        if existe:
            error = es.errorSemantico(
                key, 'La tabla ' + p_inst.nombreTabla + ' ya existe')
            p_es.agregar(error)
            self.new_output(error.tipo)
        else:
            simbolo = st.Symbol(key, p_inst.nombreTabla, 'create table', BDD)
            p_st.add(simbolo)
            createTable(BDD, nTB, cantCol)
            self.new_output("SE HA CREADO LA TABLA \'" + p_inst.nombreTabla +
                            "\' EN BASE DE DATOS \'" + BDD + "\'.")
Esempio n. 6
0
 def do_create_database(self, p_inst, p_st, p_es):
     key = 'CBD_' + p_inst.idData
     simbolo = st.Symbol(key, p_inst.idData, 'create', '','','')
     existe = p_st.get(key)
     if existe and p_inst.Replace:
         p_st.add(simbolo)
     elif existe and p_inst.IfNot:
         p_st.add(simbolo)
     elif not existe:
         p_st.add(simbolo)
Esempio n. 7
0
 def do_use(self, p_inst, p_st, p_es):
     sKey = 'CBD_' + p_inst.nombre
     existe = p_st.get(sKey)
     if existe:
         simbolo = st.Symbol('UDB_' + p_inst.nombre, p_inst.nombre, 'use', '','')
         p_st.add(simbolo)
         self.new_output("SE USARÁ LA BASE DE DATOS \'" + p_inst.nombre + "\'")
         self.use_db = p_inst.nombre
     else:
         error = es.errorSemantico('UDB_' + p_inst.nombre, 'La base de datos ' + p_inst.nombre + ' no existe')
         p_es.agregar(error)
         self.new_output(error.tipo)
Esempio n. 8
0
 def do_use(self, p_inst, p_st, p_es):
     print('USAR BASE DE DATOS')
     sKey = 'CBD_' + p_inst.nombre
     existe = p_st.get(sKey)
     if existe:
         simbolo = st.Symbol('UDB_' + p_inst.nombre, p_inst.nombre, 'use',
                             '')
         p_st.add(simbolo)
     else:
         error = es.errorSemantico(
             'UDB_' + p_inst.nombre,
             'La base de datos ' + p_inst.nombre + ' no existe')
         p_es.agregar(error)
Esempio n. 9
0
    def do_drop_db(self, p_inst, p_st, p_es):
        sKey = 'CBD_' + p_inst.nombre
        existe = p_st.get(sKey)

        if existe:
            simbolo = st.Symbol('DDB_' + p_inst.nombre, p_inst.nombre, 'drop',
                                '')
            p_st.add(simbolo)
            dropDatabase(p_inst.nombre)
        elif not existe and not p_inst.exist:
            error = es.errorSemantico(
                'DDB_' + p_inst.nombre,
                'La base de datos ' + p_inst.nombre + ' no existe')
            p_es.agregar(error)
Esempio n. 10
0
    def do_alter_db(self, p_inst, p_st, p_es):
        key = 'CBD_' + p_inst.nombreDB
        existe = p_st.get(key)
        if existe:
            newDB = p_inst.operacion.cadena
            key = 'ADB_' + p_inst.nombreDB
            simbolo = st.Symbol(key, p_inst.nombreDB, 'Alter database', newDB,'','')
            p_st.add(simbolo)
            alterDatabase(p_inst.nombreDB, newDB)

        else:
            error = es.errorSemantico('ADB_' + p_inst.nombreDB, 'La base de datos ' + p_inst.nombreDB + ' no existe')
            p_es.agregar(error)

        print('a')
Esempio n. 11
0
    def do_index(self, p_inst, p_st, p_es):
        key = 'CI_' + p_inst.name
        existe = p_st.get(key)
        ckey = 'CTB_' + p_inst.table + '_'
        existet = p_st.get(ckey)

        if existe == False and existet != False:
            if isinstance(p_inst, Index):
                if p_inst.Unique == True:
                    simbolo = st.Symbol(
                        key, p_inst.name, 'INDEX', p_inst.Lindex,
                        'Se utiliza tabla: ' + p_inst.table + '<br>' +
                        'Index tipo: ' + 'Unique', '')
                elif p_inst.Using == True:
                    simbolo = st.Symbol(
                        key, p_inst.name, 'INDEX', p_inst.Lindex,
                        'Se utiliza tabla: ' + p_inst.table + '<br>' +
                        'Metodo: ' + 'Using Hash', '')
                else:
                    simbolo = st.Symbol(
                        key, p_inst.name, 'INDEX', p_inst.Lindex,
                        'Se utiliza tabla: ' + p_inst.table + '<br>', '')
            elif isinstance(p_inst, IndexW):
                simbolo = st.Symbol(
                    key, p_inst.name, 'INDEX', p_inst.Lindex,
                    'Se utiliza tabla: ' + p_inst.table + '<br>', '')
            elif isinstance(p_inst, IndexMM):
                simbolo = st.Symbol(
                    key, p_inst.name, 'INDEX',
                    str(p_inst.major) + ',' + str(p_inst.minor),
                    'Se utiliza tabla: ' + p_inst.table + '<br>', '')
            elif isinstance(p_inst, IndexOrden):
                if p_inst.Orden == 'ANF':
                    p_inst.Orden = 'ASC NULLS FIRST'
                elif p_inst.Orden == 'ANL':
                    p_inst.Orden = 'ASC NULLS LAST'
                elif p_inst.Orden == 'DNF':
                    p_inst.Orden = 'DESC NULLS FIRST'
                elif p_inst.Orden == 'DNL':
                    p_inst.Orden = 'DESC NULLS LAST'
                elif p_inst.Orden == 'NF':
                    p_inst.Orden = 'NULLS FIRST'
                elif p_inst.Orden == 'NL':
                    p_inst.Orden = 'NULLS LAST'
                simbolo = st.Symbol(
                    key, p_inst.name, 'INDEX', p_inst.valor,
                    'Se utiliza tabla: ' + p_inst.table + '<br>' + 'Orden: ' +
                    p_inst.Orden, '')

            if existe == False:
                p_st.add(simbolo)
                self.new_output("SE CREO CON EXITO EL INDICE:" + p_inst.name)

        else:
            self.new_output("EL INDICE QUE SE DESEA AGREGAR YA EXISTE")
Esempio n. 12
0
    def do_drop_db(self, p_inst, p_st, p_es):
        sKey = 'CBD_' + p_inst.nombre
        existe = p_st.get(sKey)

        if existe:
            simbolo = st.Symbol('DDB_' + p_inst.nombre, p_inst.nombre, 'drop',
                                '')
            p_st.add(simbolo)
            dropDatabase(p_inst.nombre)
            self.new_output("BASE DE DATOS \'" + p_inst.nombre +
                            "\' HA SIDO ELIMINADA EXITOSAMENTE.")
        elif not existe and not p_inst.exist:
            error = es.errorSemantico(
                'DDB_' + p_inst.nombre,
                'La base de datos ' + p_inst.nombre + ' no existe')
            p_es.agregar(error)
            self.new_output(error.tipo)
Esempio n. 13
0
    def do_create_database(self, p_inst, p_st, p_es):
        print('CREAR BASE DE DATOS')
        key = 'CBD_' + p_inst.idData
        simbolo = st.Symbol(key, p_inst.idData, 'create', '')
        existe = p_st.get(key)
        if existe and p_inst.Replace:
            p_st.add(simbolo)
            createDatabase(p_inst.idData)
        elif existe and p_inst.IfNot:
            p_st.add(simbolo)
            createDatabase(p_inst.idData)
        elif not existe:
            p_st.add(simbolo)
            createDatabase(p_inst.idData)

        else:
            error = es.errorSemantico(
                key, 'La base de datos ' + p_inst.idData + ' ya existe')
            p_es.agregar(error)
        print('hola')
Esempio n. 14
0
    def do_insert_tb(self, p_inst, p_st, p_es):
        valor2 = 0
        list = []
        listI = []
        for keys, value in p_st.symbols.items():
            if value.id == p_inst.tabla:
                BDD = value.value

        for keys, value in p_st.symbols.items():
            if value.type == 'use':
                valor2 = 1
                list.append(value.id)

        if valor2 == 0:
            error = es.errorSemantico(
                'ITB_' + p_inst.tabla,
                'No se ha seleccionado ninguna base de datos para crear la tabla '
                + p_inst.tabla)
            p_es.agregar(error)
        else:
            BDDU = list.pop()
            if BDDU == BDD:
                key = 'ITB_' + p_inst.tabla
                simbolo = st.Symbol(key, p_inst.tabla, 'insert table', BDD)
                p_st.add(simbolo)
                for val in p_inst.valores:
                    if isinstance(val, Numero) or isinstance(
                            val, Decimal) or isinstance(
                                val, bool) or isinstance(val, Cadena):
                        listI.append(val.valor)
                insert(BDD, p_inst.tabla, listI)
            else:
                error = es.errorSemantico(
                    'ITB_' + p_inst.tabla,
                    'La tabla ' + p_inst.tabla + ' no existe')
                p_es.agregar(error)
Esempio n. 15
0
 def do_create_database(self, p_inst, p_st, p_es):
     key = 'CBD_' + p_inst.idData
     simbolo = st.Symbol(key, p_inst.idData, 'create', '')
     existe = p_st.get(key)
     if existe and p_inst.Replace:
         p_st.add(simbolo)
         createDatabase(p_inst.idData)
         self.new_output("BASE DE DATOS \'" + p_inst.idData +
                         "\' HA SIDO CREADA EXITOSAMENTE.")
     elif existe and p_inst.IfNot:
         p_st.add(simbolo)
         createDatabase(p_inst.idData)
         self.new_output("BASE DE DATOS \'" + p_inst.idData +
                         "\' HA SIDO CREADA EXITOSAMENTE.")
     elif not existe:
         p_st.add(simbolo)
         createDatabase(p_inst.idData)
         self.new_output("BASE DE DATOS \'" + p_inst.idData +
                         "\' HA SIDO CREADA EXITOSAMENTE.")
     else:
         error = es.errorSemantico(
             key, 'La base de datos ' + p_inst.idData + ' ya existe')
         p_es.agregar(error)
         self.new_output(error.tipo)
Esempio n. 16
0
    def do_index(self, p_inst, p_st, p_es):
        key = 'CI_' + p_inst.name
        if isinstance(p_inst, Index):
            if p_inst.Unique == True:
                simbolo = st.Symbol(key, p_inst.name, 'INDEX', p_inst.Lindex,
                                    'Index tipo: ' + 'Unique', '')
            elif p_inst.Using == True:
                simbolo = st.Symbol(key, p_inst.name, 'INDEX', p_inst.Lindex,
                                    'Metodo: ' + 'Using Hash', '')
            else:
                simbolo = st.Symbol(key, p_inst.name, 'INDEX', p_inst.Lindex,
                                    '', '')
        elif isinstance(p_inst, IndexW):
            simbolo = st.Symbol(key, p_inst.name, 'INDEX', p_inst.Lindex, '',
                                '')
        elif isinstance(p_inst, IndexMM):
            simbolo = st.Symbol(key, p_inst.name, 'INDEX',
                                str(p_inst.major) + ',' + str(p_inst.minor),
                                '', '')
        elif isinstance(p_inst, IndexOrden):
            if p_inst.Orden == 'ANF':
                p_inst.Orden = 'ASC NULLS FIRST'
            elif p_inst.Orden == 'ANL':
                p_inst.Orden = 'ASC NULLS LAST'
            elif p_inst.Orden == 'DNF':
                p_inst.Orden = 'DESC NULLS FIRST'
            elif p_inst.Orden == 'DNL':
                p_inst.Orden = 'DESC NULLS LAST'
            elif p_inst.Orden == 'NF':
                p_inst.Orden = 'NULLS FIRST'
            elif p_inst.Orden == 'NL':
                p_inst.Orden = 'NULLS LAST'

            simbolo = st.Symbol(key, p_inst.name, 'INDEX', p_inst.valor,
                                'Orden: ' + p_inst.Orden, '')

        existe = p_st.get(key)
        if not existe:
            p_st.add(simbolo)
Esempio n. 17
0
 def do_insert_tb(self, p_inst, p_st, p_es):
     key = 'ITB_'+p_inst.tabla
     simbolo = st.Symbol(key, p_inst.tabla, 'insert table', str(p_inst.valores).replace('\'',' '),'','')
     p_st.add(simbolo)
Esempio n. 18
0
 def do_create_type(self, p_inst, p_st):
     key = 'CTP_' + p_inst.idtype
     simbolo = st.Symbol(key, p_inst.idtype, 'Type', p_inst.valores,'','')
     existe = p_st.get(key)
     if not existe:
         p_st.add(simbolo)