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)
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)
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 + "\'.")
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)
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)
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)
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')
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)
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)
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')
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)
def do_select(self, p_inst, p_st, p_es, ct_global): valor2 = 0 list = [] for keys, value in p_st.symbols.items(): if value.type == 'use': valor2 = 1 list.append(value.id) if valor2 == 0: error = es.errorSemantico('SLT_', 'No se ha seleccionado ninguna base de datos para realizar el select') p_es.agregar(error) self.new_output(error.tipo) else: tablas_listado = [] for keys, value in p_st.symbols.items(): if value.value == self.use_db and value.type == 'create table': tablas_listado.append(value.id) if value.value == self.use_db and value.type == 'drop table': tablas_listado.remove(value.id) for table in p_inst.pfrom: ans = self.search_table(tablas_listado, table.valor) if ans is False: error = es.errorSemantico('SLT_', 'No se puede ejecutar la instrucción SELECT. Una de las tabla \'' + table.valor + '\' no existe en la base de datos.') p_es.agregar(error) self.new_output(error.tipo) return if p_inst.valores == '*': out = "" for table in p_inst.pfrom: output = extractTable(self.use_db, table.valor) if len(output) > 0: out += table.valor + '\n' out += '---------------------------------------\n' for item in output: out += str(item) + '\n' out += '\n' else: out += table.valor + '\n' out += '---------------------------------------\n' out += '... TABLA VACIA ...' + '\n\n' self.new_output(out) else: listado = [] listado2 = [] for col in p_inst.valores: listado.append(col.valor.valor) for col in p_inst.valores: if col.alias is None: listado2.append(col.valor.valor) else: listado2.append(col.alias.valor) out = "" for table in p_inst.pfrom: output = extractRow(self.use_db, table.valor, listado) if len(output) > 0: out += table.valor + '\n' out += str(listado2) + '\n' out += '---------------------------------------\n' for item in output: out += str(item) + '\n' out += '\n' else: out += table.valor + '\n' out += str(listado2) + '\n' out += '---------------------------------------\n' out += '... TABLA VACIA ...' + '\n\n' self.new_output(out)