def ejecutar(self, TS, Errores): #falta la funcion de insertar solo ciertas columnas bd = os.environ['DB'] tipos = [] #verifica que los tipos coincidan val =[] for columna in self.values: columna.ejecutar(TS, Errores) val.append(columna.val) tipos.append(columna.type) respuesta = jm.insert(bd,self.table_id,val) if respuesta == 2: # noexisteDB Errores.insertar(Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: ' + str(bd) + ' connection_does_not_exist\n' elif respuesta == 3: # noexisteTB Errores.insertar(Nodo_Error('42P01', 'undefined_table', self.fila, self.columna)) return '42P01: ' + str(self.table_id) +' undefined_table \n' elif respuesta == 5: #noColDiferente Errores.insertar(Nodo_Error('HV008', 'fdw_invalid_column_number', self.fila, self.columna)) return 'HV008: fdw_invalid_column_number \n' elif respuesta == 4: #Pk_duplicada Errores.insertar(Nodo_Error('42710', 'duplicate_object', self.fila, self.columna)) return '42710: duplicate_object \n' elif respuesta == 1: # error Errores.insertar(Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: return 'Se ingresaron los registros exitosamente \n'
def ejecutar(self, TS, Errores): #No se toca el owner para esta fase if self.if_not_exist: if self.nombre_DB in TypeChecker.showDataBases(): Errores.insertar( err.Nodo_Error('42P04', 'duplicated database', self.fila, self.columna)) return '42P04: duplicated database\n' if self.or_replace: respuesta = TypeChecker.dropDataBase(self.nombre_DB) if respuesta == 1: Errores.insertar( err.Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error\n' if self.mode > 5 or self.mode < 1: Errores.insertar( err.Nodo_Error('Semantico', 'El modo debe estar entre 1 y 5', self.fila, self.columna)) return 'Error semantico: El modo debe estar entre 1 y 5\n' respuesta = TypeChecker.createDataBase(self.nombre_DB, self.mode, self.owner) if respuesta == 2: Errores.insertar( err.Nodo_Error('42P04', 'duplicated database', self.fila, self.columna)) return '42P04: duplicated database\n' if respuesta == 1: Errores.insertar( err.Nodo_Error('P0000', 'plpgsql_error', self.fila, self.columna)) return 'P0000: plpgsql_error\n' return 'BASE DE DATOS %s CREADA\n' % self.nombre_DB
def ejecutar(self, TS, Errores): nombre_DB = os.environ['DB'] if nombre_DB is None: Errores.insertar( err.Nodo_Error( 'P0002', 'no data found, no hay una base de datos seleccionada', self.fila, self.columna)) return 'P0002: no data found, no hay una base de datos seleccionada\n' respuesta = TypeChecker.dropTable(nombre_DB, self.nombre_tabla) if respuesta != 0: if respuesta == 1: Errores.insertar( err.Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error\n' elif respuesta == 2: Errores.insertar( err.Nodo_Error( '3D000', 'No existe base de datos <<%s>>' % nombre_DB, self.fila, self.columna)) return '3D000: No existe base de datos <<%s>>\n' % nombre_DB else: Errores.insertar( err.Nodo_Error( '42P01', 'No existe la tabla <<%s>>' % self.nombre_tabla, self.fila, self.columna)) return '42P01: No existe la tabla <<%s>>\n' % self.nombre_tabla return 'Tabla <<%s>> eliminada\n' % self.nombre_tabla
def p_error(p): if not p: print('end of file') ListaErrores.insertar(err.Nodo_Error("Sintactico", "Se esperaba mas pero llega fin de texto", input.count('\n'), len(input))) return ListaErrores.insertar(err.Nodo_Error("Sintactico", str(p.value), p.lineno, find_column(input, p))) while True: tok = parser.token() if not tok or tok.type == 'pyc': break
def ejecutar(self, TS, Errores): if not self.id in jm.showDatabases(): Errores.insertar(Nodo_Error("TytusDB: 08003", "\'" + str(self.id) + "\' connection_does_not_exist", self.fila, self.columna)) return 'TytusDB: 08003, '+ str(self.id) + ' connection_does_not_exist' else: os.environ['DB'] = str(self.id) return 'Base de Datos ' + str(self.id) + ' seleccionada.'
def ejecutar(self, TS, Errores): respuesta = TypeChecker.dropDataBase(self.nombre_DB) if respuesta == 2: #Base de datos no existente if self.if_exists: return 'NOTICIA: BASE DE DATOS %s, NO EXISTENTE\n' % self.nombre_DB Errores.insertar( err.Nodo_Error( '3D000', 'No existe base de datos <<%s>>' % self.nombre_DB, self.fila, self.columna)) return '3D000: No existe base de datos <<%s>>\n' % self.nombre_DB if respuesta == 1: #Error interno Errores.insertar( err.Nodo_Error('P0000', 'plpgsql_error', self.fila, self.columna)) return 'P0000: plpgsql_error\n' return 'BASE DE DATOS %s ELIMINADA\n' % self.nombre_DB
def ejecutar(self, TS, Errores): simbolo = TS.obtener(self.nombre) if simbolo is None: Errores.insertar( Nodo_Error("Semantico", "No existe variable " + self.nombre, self.fila, self.columna)) return TIPO_DATOS.ERROR return simbolo.tipo
def ejecutar(self, TS, Errores): if self.nuevo_nombre_DB is not None: respuesta = TypeChecker.alterDataBase(self.nombre_DB, self.nuevo_nombre_DB) if respuesta == 1: Errores.insertar( err.Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error\n' elif respuesta == 2: Errores.insertar( err.Nodo_Error( '3D000', 'No existe base de datos <<%s>>' % self.nombre_DB, self.fila, self.columna)) return '3D000: No existe base de datos <<%s>>' % self.nombre_DB elif respuesta == 3: Errores.insertar( err.Nodo_Error('42P04', 'duplicated database', self.fila, self.columna)) return '42P04: duplicated database\n' return 'Base de datos %s, renombrada a: %s' % ( self.nombre_DB, self.nuevo_nombre_DB) else: if self.current_user: return 'No hay implementacion para esto porque no se maneja usuario\n' elif self.session_user: return 'No hay implementacion para esto porque no se maneja usuario\n' else: respuesta = TypeChecker.alterDataBaseOwner( self.nombre_DB, self.owner) if respuesta == 1: Errores.insertar( err.Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error\n' elif respuesta == 2: Errores.insertar( err.Nodo_Error( '3D000', 'No existe base de datos <<%s>>' % self.nombre_DB, self.fila, self.columna)) return '3D000: No existe base de datos <<%s>>' % self.nombre_DB return 'Owner de base de datos <<%s>>, cambiado a <<%s>>' % ( self.nombre_DB, self.owner)
def ejecutar(self, TS, Errores): respuesta = TypeChecker.registarEnum(self.nombre_type, self.lista_enum) if respuesta != 0: Errores.insertar( err.Nodo_Error( '42710', 'duplicate_object, ya existe un tipo <<%s>>' % self.nombre_type, self.fila, self.columna)) return '42710: duplicate_object, ya existe un tipo <<%s>>\n' % self.nombre_type return 'Type <<%s>> creado satisfactoriamente\n' % self.nombre_type
def ejecutar(self, TS, Errores): tipo = self.Exp1.ejecutar(TS, Errores) if tipo == TIPO_DATOS.INT or tipo == TIPO_DATOS.CHAR or tipo == TIPO_DATOS.DOUBLE or tipo == TIPO_DATOS.DOUBLE: return tipo else: Errores.insertar( Nodo_Error("Semantico", "No es posible incremento/decremento", self.fila, self.columna)) return TIPO_DATOS.ERROR
def t_entero(t): r'\d+' try: t.value = int(t.value) except ValueError: print("El valor de integer es muy grande %d", t.value) ListaErrores.insertar(err.Nodo_Error("Lexico", "El valor de integer es muy grande '%s'" % str(t.value), t.lineno, find_column(input, t))) t.value = 0 return t
def p_error(p): if not p: print('end of file') return ListaErrores.insertar( err.Nodo_Error("Sintactico", str(p.value), p.lineno, find_column(input, p))) while True: tok = parser.token() if not tok or tok.type == 'pyc': break
def ejecutar(self, TS, Errores): tipo = self.Exp.ejecutar(TS, Errores) if self.op == '~': if tipo == TIPO_DATOS.INT or tipo == TIPO_DATOS.CHAR: return TIPO_DATOS.INT else: Errores.insertar( Nodo_Error( "Semantico", "No es posible operador unario " + self.op + ' con tipo de dato ' + str(tipo.nombre), self.fila, self.columna)) return TIPO_DATOS.ERROR else: if tipo == TIPO_DATOS.INT or tipo == TIPO_DATOS.CHAR or tipo == TIPO_DATOS.DOUBLE or tipo == TIPO_DATOS.DOUBLE: return TIPO_DATOS.INT else: Errores.insertar( Nodo_Error( "Semantico", "No es posible operador unario " + self.op + ' con tipo de dato ' + str(tipo.nombre), self.fila, self.columna)) return TIPO_DATOS.ERROR
def ejecutar(self, TS, Errores): tipo = self.ejecutar(TS, Errores) if not (tipo == TIPO_DATOS.INT or tipo == TIPO_DATOS.CHAR or tipo == TIPO_DATOS.DOUBLE or tipo == TIPO_DATOS.DOUBLE): Errores.insertar( Nodo_Error( "Semantico", "La el tipo de condicion no es valido en ternario ", self.fila, self.columna)) return TIPO_DATOS.ERROR tipo2 = self.Exp1.ejecutar(TS, Errores) tipo3 = self.Exp2.ejecutar(TS, Errores) if tipo == TIPO_DATOS.ERROR or tipo2 == TIPO_DATOS.ERROR or tipo3 == TIPO_DATOS.ERROR: return TIPO_DATOS.ERROR
def ejecutar(self, TS, Errores): tipo1 = self.Exp1.ejecutar(TS, Errores) tipo2 = self.Exp2.ejecutar(TS, Errores) if (tipo1 == TIPO_DATOS.INT or tipo1 == TIPO_DATOS.CHAR) and (tipo2 == TIPO_DATOS.INT or tipo2 == TIPO_DATOS.CHAR): return TIPO_DATOS.INT else: Errores.insertar( Nodo_Error( "Semantico", "No es posible operacion entre " + str(tipo1.nombre) + ' ' + self.op + ' ' + str(tipo2.nombre), self.fila, self.columna)) return TIPO_DATOS.ERROR
def analizar(self, TS, Errores): tipo1 = self.Exp1.analizar(TS, Errores) tipo2 = self.Exp2.analizar(TS, Errores) if (tipo1 == TIPO_DATOS.STRING or tipo1 == TIPO_DATOS.INT or tipo1 == TIPO_DATOS.CHAR or tipo1 == TIPO_DATOS.FLOAT or tipo1 == TIPO_DATOS.DOUBLE) and ( tipo2 == TIPO_DATOS.STRING or tipo2 == TIPO_DATOS.INT or tipo2 == TIPO_DATOS.CHAR or tipo2 == TIPO_DATOS.FLOAT or tipo2 == TIPO_DATOS.DOUBLE): return TIPO_DATOS.INT else: Errores.insertar( Nodo_Error( "Semantico", "No es posible operacion entre " + str(tipo1) + ' ' + self.op + ' ' + str(tipo2), self.fila, self.columna)) return TIPO_DATOS.ERROR
def ejecutar(self, TS, Errores): bd = os.environ['DB'] if self.condicion != '': self.condicion.ejecutar(TS, Errores) valor = self.condicion.exp2.val col = self.condicion.exp1.val #se tiene que verificar el index de la columna res= jm.extractTable(bd,self.id) c = 0 valores = [] for n in res: for k in n: if k == valor: valores.append(c) c += 1 respuesta = jm.delete(bd,self.id,valores) if respuesta == 2: # noexisteDB Errores.insertar(Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: connection_does_not_exist\n' elif respuesta == 3: # noexisteTB Errores.insertar(Nodo_Error('HV00R', 'fdw_table_not_found', self.fila, self.columna)) return 'HV00R: fdw_table_not_found \n' elif respuesta == 4: # noexistePk Errores.insertar(Nodo_Error('P0002', 'no_data_found ', self.fila, self.columna)) return 'P0002: no_data_found \n' elif respuesta == 1: # error Errores.insertar(Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: return 'Se eliminaron los registros de la tabla \n' else: #elimina todos los registros respuesta = jm.truncate(bd, self.id) if respuesta == 2: # noexisteDB Errores.insertar(Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: ' + str(bd) +' connection_does_not_exist\n' elif respuesta == 3: # noexisteTB Errores.insertar(Nodo_Error('42P01', 'undefined_table', self.fila, self.columna)) return '42P01: ' + str(self.id) +'undefined_table \n' elif respuesta == 1: # error Errores.insertar(Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: return 'Se eliminaron los registros de la tabla ' + str(self.id)
def ejecutar(self, TS, Errores): bd = os.environ['DB'] registros = {} #se crea el diccionario de registros for i in self.list_exp: i.ejecutar(TS, Errores) registros[i.exp1.val] = i.exp2.val print(registros) if self.clausula != None: try: respuesta = jm.update(bd, table_id, registros) if respuesta == 2: #noDB Errores.insertar( Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: connection_does_not_exist\n' elif respuesta == 3: #noTB Errores.insertar( Nodo_Error('HV00R', 'fdw_table_not_found', self.fila, self.columna)) return 'HV00R: fdw_table_not_found \n' elif respuesta == 4: #noPK Errores.insertar( Nodo_Error('P0002', 'no_data_found ', self.fila, self.columna)) return 'P0002: no_data_found \n' elif respuesta == 1: #error Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' elif respuesta == 0: return 'Se actualizaron los registros de la tabla \n' except: Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: try: respuesta = jm.update(bd, self.table_id, registros) if respuesta == 2: #noDB Errores.insertar( Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: connection_does_not_exist\n' elif respuesta == 3: #noTB Errores.insertar( Nodo_Error('HV00R', 'fdw_table_not_found', self.fila, self.columna)) return 'HV00R: fdw_table_not_found \n' elif respuesta == 4: #noPK Errores.insertar( Nodo_Error('P0002', 'no_data_found ', self.fila, self.columna)) return 'P0002: no_data_found \n' elif respuesta == 1: #error Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' elif respuesta == 0: return 'Se actualizaron los registros de la tabla \n' except: Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n'
def ejecutar(self, TS, Errores): bd = os.environ['DB'] infoTB = tp.showColumns(bd, self.id) #datos de tabla nombreCol = list(infoTB.keys()) TiposCol = list(infoTB.values()) if self.condicion != '': col = self.condicion.exp1.id op = self.condicion.op valor = self.condicion.exp2.val if col in nombreCol: noColumna = nombreCol.index(col) #indice col npPK = tp.showPrimaryKeys(bd, self.id) #retorna nombre indicePK = nombreCol.index(npPK[0]) #indice pk try: res = wh.evaluar(bd, self.id, col, op, valor, noColumna, indicePK, 'delete') respuesta = jm.delete(bd, self.id, res) if respuesta == 2: # noexisteDB Errores.insertar( Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: connection_does_not_exist\n' elif respuesta == 3: # noexisteTB Errores.insertar( Nodo_Error('HV00R', 'fdw_table_not_found', self.fila, self.columna)) return 'HV00R: fdw_table_not_found \n' elif respuesta == 4: # noexistePk Errores.insertar( Nodo_Error('P0002', 'no_data_found ', self.fila, self.columna)) return 'P0002: no_data_found \n' elif respuesta == 1: # error Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: return 'Se eliminaron los registros de la tabla \n' except: Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: Errores.insertar( Nodo_Error('42P10', 'invalid_column_reference ', self.fila, self.columna)) return '42P10 : invalid_column_reference \n' else: #elimina todos los registros respuesta = jm.truncate(bd, self.id) if respuesta == 2: # noexisteDB Errores.insertar( Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: ' + str(bd) + ' connection_does_not_exist\n' elif respuesta == 3: # noexisteTB Errores.insertar( Nodo_Error('42P01', 'undefined_table', self.fila, self.columna)) return '42P01: ' + str(self.id) + 'undefined_table \n' elif respuesta == 1: # error Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: return 'Se eliminaron los registros de la tabla ' + str( self.id)
def ejecutar(self, TS, Errores): if self.op_type == 'valor': return self elif self.op_type == 'unario': self.val.ejecutar(TS, Errores) if self.type == '-': self.val = -self.val.val return self elif self.op_type == 'as' or self.op_type == 'in' or self.op_type == 'agg': self.val.ejecutar(TS, Errores) self.asid.ejecutar(TS, Errores) self.asid = self.asid.id return self elif self.op_type == 'math': if self.function == 'ceil' or self.function == 'ceiling': self.val.ejecutar(TS, Errores) if isinstance(self.val.val, int): self.val = m.__ceil__(self.val.val) else: self.val = m.ceil(self.val.val) elif self.function == 'abs': self.val = m.fabs(self.val.val) elif self.function == 'cbrt': self.val = m.ceil(self.val.val**(1 / 3)) elif self.function == 'degrees': self.val = m.degrees(self.val.val) elif self.function == 'div': self.val = m.exp(self.val.val) elif self.function == 'exp': self.val = m.exp(self.val.val) elif self.function == 'factorial': self.val = m.factorial(self.val.val) elif self.function == 'floor': self.val = m.floor(self.val.val) elif self.function == 'gcd': self.val = m.gcd(self.val.val) elif self.function == 'ln': self.val = m.log(self.val.val) elif self.function == 'log': self.val = m.log10(self.val.val) elif self.function == 'pi': self.val = m.pi return self elif self.op_type == 'trigo': if self.function == 'acos': self.val = m.acos(self.val.val) elif self.function == 'acosd': self.val = m.degrees(m.acos(self.val.val)) elif self.function == 'asin': self.val = m.asin(self.val.val) elif self.function == 'asind': self.val = m.degrees(m.asin(self.val.val)) elif self.function == 'atan': self.val = m.atan(self.val.val) elif self.function == 'atand': self.val = m.degrees(m.atan(self.val.val)) elif self.function == 'cos': self.val = m.cos(self.val.val) elif self.function == 'cosd': self.val = m.cos(m.radians(self.val.val)) elif self.function == 'sin': self.val = m.sin(self.val.val) elif self.function == 'sind': self.val = m.sin(m.radians(self.val.val)) elif self.function == 'tan': self.val = m.tan(self.val.val) elif self.function == 'tand': self.val = m.tan(m.radians(self.val.val)) return self elif self.op_type == 'iden': return self elif self.op_type == 'Aritmetica': val1 = self.exp1.ejecutar(TS, Errores) val2 = self.exp2.ejecutar(TS, Errores) #----------------------------------------------------------------------> Se validan operaciones con int if isinstance(val1.val, int): if isinstance(val2.val, int): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, float): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0.0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, bool): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2 != 0 or val2 is not False: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self else: Errores.insertar( Nodo_Error( "Semantico", "No es posible ejecutar la operacion \'" + str(self.op) + "\' con los tipos de datos \'" + str(val1.type) + "\' y " + "\'" + str(val2.type) + "\' en", self.line, self.column)) return TIPO_DATOS.ERROR #----------------------------------------------------------------------> Se validan operaciones con FLOAT elif isinstance(val1.val, float): if isinstance(val2.val, int): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, float): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0.0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, bool): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2 != 0 or val2 is not False: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self else: Errores.insertar( Nodo_Error( "Semantico", "No es posible ejecutar la operacion \'" + str(self.op) + "\' con los tipos de datos \'" + str(val1.type) + "\' y " + "\'" + str(val2.type) + "\' en", self.line, self.column)) return TIPO_DATOS.ERROR # ----------------------------------------------------------------------> Se validan operaciones con BOOLEAN elif isinstance(val1.val, bool): if isinstance(val2.val, int): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, float): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0.0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, bool): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2 != 0 or val2 is not False: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self else: Errores.insertar( Nodo_Error( "Semantico", "No es posible ejecutar la operacion \'" + str(self.op) + "\' con los tipos de datos \'" + str(val1.type) + "\' y " + "\'" + str(val2.type) + "\' en", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op_type == 'Relacional': val1 = self.exp1.ejecutar(TS, Errores) val2 = self.exp2.ejecutar(TS, Errores) # ----------------------------------------------------------------------> Se validan operaciones con int while val1 != TIPO_DATOS.ERROR: if isinstance(val1.val, int): if isinstance(val2.val, int): if self.op == '<': self.val = val1.val < val2.val elif self.op == '>': self.val = val1.val > val2.val elif self.op == '<>': self.val = val1.val != val2.val elif self.op == '!=': self.val = val1.val != val2.val elif self.op == '>=': self.val = val1.val >= val2.val elif self.op == '<=': self.val = val1.val <= val2.val elif self.op == '=': self.val = val1.val == val2.val return self elif isinstance(val2.val, float): if self.op == '<': self.val = val1.val < val2.val elif self.op == '>': self.val = val1.val > val2.val elif self.op == '<>': self.val = val1.val != val2.val elif self.op == '!=': self.val = val1.val != val2.val elif self.op == '>=': self.val = val1.val >= val2.val elif self.op == '<=': self.val = val1.val <= val2.val elif self.op == '=': self.val = val1.val == val2.val return self elif isinstance(val2.val, str): if self.op == '<': self.val = val1.val < int(val2.val) elif self.op == '>': self.val = val1.val > int(val2.val) elif self.op == '<>': self.val = val1.val != int(val2.val) elif self.op == '!=': self.val = val1.val != int(val2.val) elif self.op == '>=': self.val = val1.val >= int(val2.val) elif self.op == '<=': self.val = val1.val <= int(val2.val) elif self.op == '=': self.val = val1.val == int(val2.val) return self else: Errores.insertar( Nodo_Error( "Semantico", "No es posible ejecutar la operacion '" + str(self.op) + "' con los tipos de datos \'" + str(val2.type) + "\' y " + "'" + str(val2.type) + "' en", self.line, self.column)) return TIPO_DATOS.ERROR # ----------------------------------------------------------------------> Se validan operaciones con int elif isinstance(val1.val, float): if isinstance(val2.val, int): if self.op == '<': self.val = val1.val < val2.val elif self.op == '>': self.val = val1.val > val2.val elif self.op == '<>': self.val = val1.val != val2.val elif self.op == '!=': self.val = val1.val != val2.val elif self.op == '>=': self.val = val1.val >= val2.val elif self.op == '<=': self.val = val1.val <= val2.val elif self.op == '=': self.val = val1.val == val2.val return self elif isinstance(val2.val, float): if self.op == '<': self.val = val1.val < val2.val elif self.op == '>': self.val = val1.val > val2.val elif self.op == '<>': self.val = val1.val != val2.val elif self.op == '!=': self.val = val1.val != val2.val elif self.op == '>=': self.val = val1.val >= val2.val elif self.op == '<=': self.val = val1.val <= val2.val elif self.op == '=': self.val = val1.val == val2.val return self elif isinstance(val2.val, str): if self.op == '<': self.val = val1.val < float(val2.val) elif self.op == '>': self.val = val1.val > float(val2.val) elif self.op == '<>': self.val = val1.val != float(val2.val) elif self.op == '!=': self.val = val1.val != float(val2.val) elif self.op == '>=': self.val = val1.val >= float(val2.val) elif self.op == '<=': self.val = val1.val <= float(val2.val) elif self.op == '=': self.val = val1.val == float(val2.val) return self else: Errores.insertar( Nodo_Error( "Semantico", "No es posible ejecutar la operacion \'" + str(self.op) + "\' con los tipos de datos \'" + str(val1.type) + "\' y " + "\'" + str(val2.type) + "\' en", self.line, self.column)) return TIPO_DATOS.ERROR elif val1.op_type == 'iden': val1.val = val2.val return val1 else: return TIPO_DATOS.ERROR return TIPO_DATOS.ERROR elif self.op_type == 'Logica': val1 = self.exp1.ejecutar(TS, Errores) val2 = self.exp2.ejecutar(TS, Errores) if isinstance(val1.val, bool): if isinstance(val2.val, bool): if self.op == 'and': self.val = val1.val and val2.val elif self.op == 'or': self.val = val1.val or val2.val return self
def ejecutar(self, TS, Errores): tipo1 = self.Exp1.ejecutar(TS, Errores) tipo2 = self.Exp2.ejecutar(TS, Errores) if self.op == '+': if (tipo1 == TIPO_DATOS.INT or tipo1 == TIPO_DATOS.CHAR or tipo1 == TIPO_DATOS.FLOAT or tipo1 == TIPO_DATOS.DOUBLE) and (tipo2 == TIPO_DATOS.CHAR or tipo2 == TIPO_DATOS.INT or tipo2 == TIPO_DATOS.DOUBLE or tipo2 == TIPO_DATOS.DOUBLE): if tipo1 == TIPO_DATOS.INT and tipo2 == TIPO_DATOS.INT: self.tipo = TIPO_DATOS.INT return self.valor elif tipo1 == TIPO_DATOS.CHAR or tipo2 == TIPO_DATOS.CHAR: return TIPO_DATOS.CHAR return TIPO_DATOS.DOUBLE else: return TIPO_DATOS.CHAR elif self.op == '-' or self.op == '*': if (tipo1 == TIPO_DATOS.INT or tipo1 == TIPO_DATOS.CHAR or tipo1 == TIPO_DATOS.DOUBLE or tipo1 == TIPO_DATOS.DOUBLE) and (tipo2 == TIPO_DATOS.CHAR or tipo2 == TIPO_DATOS.INT or tipo2 == TIPO_DATOS.DOUBLE or tipo2 == TIPO_DATOS.DOUBLE): if tipo1 == TIPO_DATOS.INT and tipo2 == TIPO_DATOS.INT: return TIPO_DATOS.INT elif tipo1 == TIPO_DATOS.CHAR or tipo2 == TIPO_DATOS.CHAR: return TIPO_DATOS.INT return TIPO_DATOS.DOUBLE else: Errores.insertar( Nodo_Error( "Semantico", "No es posible operacion entre " + str(tipo1.name) + ' ' + self.op + ' ' + str(tipo2.name), self.fila, self.columna)) return TIPO_DATOS.ERROR elif self.op == '/': if (tipo1 == TIPO_DATOS.INT or tipo1 == TIPO_DATOS.CHAR or tipo1 == TIPO_DATOS.DOUBLE or tipo1 == TIPO_DATOS.DOUBLE) and (tipo2 == TIPO_DATOS.CHAR or tipo2 == TIPO_DATOS.INT or tipo2 == TIPO_DATOS.DOUBLE or tipo2 == TIPO_DATOS.DOUBLE): return TIPO_DATOS.DOUBLE else: Errores.insertar( Nodo_Error( "Semantico", "No es posible operacion entre " + str(tipo1.nombre) + ' ' + self.op + ' ' + str(tipo2.nombre), self.fila, self.columna)) return TIPO_DATOS.ERROR elif self.op == '%': if (tipo1 == TIPO_DATOS.INT or tipo1 == TIPO_DATOS.CHAR) and ( tipo2 == TIPO_DATOS.CHAR or tipo2 == TIPO_DATOS.INT): return TIPO_DATOS.INT else: Errores.insertar( Nodo_Error( "Semantico", "No es posible operacion entre " + str(tipo1.nombre) + ' ' + self.op + ' ' + str(tipo2.nombre), self.fila, self.columna)) return TIPO_DATOS.ERROR
def ejecutar(self, TS, Errores): columnas = [] col_dict = {} tuplas = [] tuplas_aux = [] ordencol = [] db = os.environ['DB'] result = 'Query from tables: ' contador = 0 tablasError = [] tableState = True #---------------------FROM if len(self.tables) != 0: for tabla in self.tables: while jm.extractTable(db, tabla) is not None: tuplas += jm.extractTable(db, tabla) col_dict += tp.showColumns(db, tabla) tablasError.append(tabla) tableState = False if tableState: #--------------------WHERE if isinstance(self.conditions, Where): self.conditions.ejecutar(TS, Errores) # ---------------------ORDER BY if self.ord is not None: for ord in self.ord: ord.ejecutar(TS, Errores) ord_dict = { 'columna': ord.columna, 'orden': ord.orden, 'nulls': ord.nulls } ordencol.append(ord_dict) if self.arguments is not None: for columna in self.arguments: columna.ejecutar(TS, Errores) if columna.op_type == 'as': if columna.val.op_type == 'valor' or \ columna.val.op_type == 'Aritmetica' or \ columna.val.op_type == 'Relacional' or \ columna.val.op_type == 'Logica' or \ columna.val.op_type == 'unario': tuplas_aux.append(columna.val.val) columnas.append(columna.asid) elif columna.op_type == 'valor': columnas.append('Columna ' + str(contador)) tuplas_aux.append(columna.val) contador = contador + 1 elif columna.op_type == 'iden': columnas.append(columna.id) else: tuplas.append(columna.val) columnas.append('Columna ' + str(contador)) contador = contador + 1 else: columnas = list(col_dict.keys()) if len(columnas) != 0: self.result_query.field_names = columnas cont = 0 if len(tuplas_aux) > 0: tuplas += [tuplas_aux] if len(tuplas) != 0: if ordencol is not None: for dic in ordencol: while dic['columna'] != columnas[cont]: cont = cont + 1 for item in ordencol: if item['orden'] == 'asc': tuplas = sorted(tuplas, key=itemgetter(cont)) else: tuplas = sorted(tuplas, key=itemgetter(cont), reverse=True) if isinstance(self.conditions, Where): new_tuplas = [] for tupla in tuplas: if self.conditions.dictionary['val'] in tupla: new_tuplas.append(tupla) tuplas = new_tuplas if len(tuplas[0]) == len(columnas): for tupla in tuplas: self.result_query.add_row(tupla) else: new_tuplas2 = [] indices = [] index = 0 for col in col_dict.keys(): if col == columnas[index]: indices.append(index) index = index + 1 for ind in indices: new_tuplas2 = list(map(itemgetter(ind), tuplas)) print(new_tuplas2) else: tabless = '' for tabla in tablasError: Errores.insertar( Nodo_Error('42P01', 'undefined_table', self.line, self.column)) tabless += str(tabla) + ' ' result = '42P01: <<' + str(tabless) + '>> UNDEFINED TABLE(S)' return result if self.tables is not []: for obj in self.tables: result += str(obj) + ' ' result += '\n' + self.result_query.get_string() return result
def ejecutar(self, TS, Errores): if self.op_type is None: return self elif self.op_type == 'iden': if TS.exists(self.id): return self Errores.insertar(Nodo_Error("Semantico", "No existe el campo \'" + self.id + "\'", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op_type == 'Aritmetica': val1 = self.exp1.ejecutar(TS, Errores) val2 = self.exp2.ejecutar(TS, Errores) #----------------------------------------------------------------------> Se validan operaciones con int if isinstance(val1.val, int): if isinstance(val2.val, int): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, float): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0.0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, bool): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2 != 0 or val2 is not False: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self else: Errores.insertar(Nodo_Error("Semantico", "No es posible ejecutar la operacion \'"+ str(self.op) +"\' con los tipos de datos \'"+str(val1.type)+"\' y " + "\'" + str(val2.type) + "\' en", self.line, self.column)) return TIPO_DATOS.ERROR #----------------------------------------------------------------------> Se validan operaciones con FLOAT elif isinstance(val1.val, float): if isinstance(val2.val, int): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, float): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0.0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, bool): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2 != 0 or val2 is not False: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self else: Errores.insertar(Nodo_Error("Semantico", "No es posible ejecutar la operacion \'"+ str(self.op) +"\' con los tipos de datos \'"+str(val1.type)+"\' y " + "\'" + str(val2.type) + "\' en", self.line, self.column)) return TIPO_DATOS.ERROR # ----------------------------------------------------------------------> Se validan operaciones con BOOLEAN elif isinstance(val1.val, bool): if isinstance(val2.val, int): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, float): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2.val != 0.0: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self elif isinstance(val2.val, bool): if self.op == '+': self.val = val1.val + val2.val elif self.op == '-': self.val = val1.val - val2.val elif self.op == '*': self.val = val1.val * val2.val elif self.op == '/': if val2 != 0 or val2 is not False: self.val = val1.val / val2.val else: Errores.insertar( Nodo_Error("Semantico", "No es posible division entre 0", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op == '%': self.val = val1.val % val2.val elif self.op == '^': self.val = pow(val1.val, val2.val) return self else: Errores.insertar(Nodo_Error("Semantico", "No es posible ejecutar la operacion \'"+ str(self.op) +"\' con los tipos de datos \'"+str(val1.type)+"\' y " + "\'" + str(val2.type) + "\' en", self.line, self.column)) return TIPO_DATOS.ERROR elif self.op_type == 'Relacional': val1 = self.exp1.ejecutar(TS, Errores) val2 = self.exp2.ejecutar(TS, Errores) # ----------------------------------------------------------------------> Se validan operaciones con int while val1 != TIPO_DATOS.ERROR: if isinstance(val1.val, int): if isinstance(val2.val, int): if self.op == '<': self.val = val1.val < val2.val elif self.op == '>': self.val = val1.val > val2.val elif self.op == '<>': self.val = val1.val != val2.val elif self.op == '!=': self.val = val1.val != val2.val elif self.op == '>=': self.val = val1.val >= val2.val elif self.op == '<=': self.val = val1.val <= val2.val elif self.op == '=': self.val = val1.val == val2.val return self elif isinstance(val2.val, float): if self.op == '<': self.val = val1.val < val2.val elif self.op == '>': self.val = val1.val > val2.val elif self.op == '<>': self.val = val1.val != val2.val elif self.op == '!=': self.val = val1.val != val2.val elif self.op == '>=': self.val = val1.val >= val2.val elif self.op == '<=': self.val = val1.val <= val2.val elif self.op == '=': self.val = val1.val == val2.val return self elif isinstance(val2.val, str): if self.op == '<': self.val = val1.val < int(val2.val) elif self.op == '>': self.val = val1.val > int(val2.val) elif self.op == '<>': self.val = val1.val != int(val2.val) elif self.op == '!=': self.val = val1.val != int(val2.val) elif self.op == '>=': self.val = val1.val >= int(val2.val) elif self.op == '<=': self.val = val1.val <= int(val2.val) elif self.op == '=': self.val = val1.val == int(val2.val) return self else: Errores.insertar(Nodo_Error("Semantico", "No es posible ejecutar la operacion '" + str( self.op) + "' con los tipos de datos \'" + str(val2.type) + "\' y " + "'" + str( val2.type) + "' en", self.line, self.column)) return TIPO_DATOS.ERROR # ----------------------------------------------------------------------> Se validan operaciones con int elif isinstance(val1.val, float): if isinstance(val2.val, int): if self.op == '<': self.val = val1.val < val2.val elif self.op == '>': self.val = val1.val > val2.val elif self.op == '<>': self.val = val1.val != val2.val elif self.op == '!=': self.val = val1.val != val2.val elif self.op == '>=': self.val = val1.val >= val2.val elif self.op == '<=': self.val = val1.val <= val2.val elif self.op == '=': self.val = val1.val == val2.val return self elif isinstance(val2.val, float): if self.op == '<': self.val = val1.val < val2.val elif self.op == '>': self.val = val1.val > val2.val elif self.op == '<>': self.val = val1.val != val2.val elif self.op == '!=': self.val = val1.val != val2.val elif self.op == '>=': self.val = val1.val >= val2.val elif self.op == '<=': self.val = val1.val <= val2.val elif self.op == '=': self.val = val1.val == val2.val return self elif isinstance(val2.val, str): if self.op == '<': self.val = val1.val < float(val2.val) elif self.op == '>': self.val = val1.val > float(val2.val) elif self.op == '<>': self.val = val1.val != float(val2.val) elif self.op == '!=': self.val = val1.val != float(val2.val) elif self.op == '>=': self.val = val1.val >= float(val2.val) elif self.op == '<=': self.val = val1.val <= float(val2.val) elif self.op == '=': self.val = val1.val == float(val2.val) return self else: Errores.insertar(Nodo_Error("Semantico", "No es posible ejecutar la operacion \'" + str( self.op) + "\' con los tipos de datos \'" + str(val1.type) + "\' y " + "\'" + str( val2.type) + "\' en", self.line, self.column)) return TIPO_DATOS.ERROR else: return TIPO_DATOS.ERROR return TIPO_DATOS.ERROR
def t_error(t): ListaErrores.insertar( err.Nodo_Error("Lexico", "Caracter no valido '%s'" % t.value[0], t.lineno, find_column(input, t))) print("Illegal character '%s'" % t.value[0]) t.lexer.skip(1)
def ejecutar(self, TS, Errores): bd = os.environ['DB'] infoTB = tp.showColumns(bd, self.table_id) # datos de tabla noCol = len(infoTB) nombreCol = list(infoTB.keys()) TiposCol = list(infoTB.values()) tipos = [] val = [] # valores noValores = len(self.values) # noValues for columna in self.values: columna.ejecutar(TS, Errores) val.append(columna.val) tipos.append(columna.type) if self.col != None: noc = len(self.col) if noc == noCol: for nn, ss in enumerate(self.col): if ss == nombreCol[nn]: pass else: Errores.insertar( Nodo_Error('42P10', 'invalid_column_reference', self.fila, self.columna)) return '42P10 : invalid_column_reference' for n, s in enumerate(TiposCol): k = list(s.values()) if (k[0] == 'integer' or k[0] == 'smallint' or k[0] == 'bigint' or k[0] == 'decimal' or k[0] == 'numeric' or k[0] == 'double' or k[0] == 'money'): if (tipos[n] == 'INT' or tipos[n] == 'DOUBLE' or tipos[n] == 'FLOAT'): if len(str(val[n])) <= k[1]: pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' elif (k[0] == 'character varying' or k[0] == 'character' or k[0] == 'varchar' or k[0] == 'char' or k[0] == 'text'): if (tipos[n] == 'CHAR' or tipos[n] == 'STR'): if len(str(val[n])) <= k[1]: pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' elif (k[0] == 'boolean'): if (tipos[n] == 'BOOLEAN'): pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' elif (k[0] == 'date'): if (tipos[n] == 'DATE'): if len(str(val[n])) <= k[1]: pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' else: res1 = tp.obtenerTiposEnum(k[0]) if val[n] in res1: pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' respuesta = jm.insert(bd, self.table_id, val) if respuesta == 2: # noexisteDB Errores.insertar( Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: ' + str(bd) + ' connection_does_not_exist\n' elif respuesta == 3: # noexisteTB Errores.insertar( Nodo_Error('42P01', 'undefined_table', self.fila, self.columna)) return '42P01: ' + str( self.table_id) + ' undefined_table \n' elif respuesta == 5: # noColDiferente Errores.insertar( Nodo_Error('HV008', 'fdw_invalid_column_number', self.fila, self.columna)) return 'HV008: fdw_invalid_column_number \n' elif respuesta == 4: # Pk_duplicada Errores.insertar( Nodo_Error('42710', 'duplicate_object', self.fila, self.columna)) return '42710: duplicate_object \n' elif respuesta == 1: # error Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: for n, s in enumerate(TiposCol): k = list(s.values()) r = nombreCol[n] #nombrecol a = k[0] #tipo dato b = k[1] #size #tts.TabladeSimbolos.insertar(r,a,b,self.table_id,self.fila,self.columna,'Insert') return 'Se ingresaron los registros exitosamente \n' else: Errores.insertar( Nodo_Error('HV008', 'fdw_invalid_column_number', self.fila, self.columna)) return 'HV008: fdw_invalid_column_number \n' else: if noValores == noCol: for n, s in enumerate(TiposCol): k = list(s.values()) if (k[0] == 'integer' or k[0] == 'smallint' or k[0] == 'bigint' or k[0] == 'decimal' or k[0] == 'numeric' or k[0] == 'double' or k[0] == 'money'): if (tipos[n] == 'INT' or tipos[n] == 'DOUBLE' or tipos[n] == 'FLOAT'): if len(str(val[n])) <= k[1]: pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' elif (k[0] == 'character varying' or k[0] == 'character' or k[0] == 'varchar' or k[0] == 'char' or k[0] == 'text'): if (tipos[n] == 'CHAR' or tipos[n] == 'STR'): if len(str(val[n])) <= k[1]: pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' elif (k[0] == 'boolean'): if (tipos[n] == 'BOOLEAN'): pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' elif (k[0] == 'date'): if (tipos[n] == 'DATE'): if len(str(val[n])) <= k[1]: pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' else: res1 = tp.obtenerTiposEnum(k[0]) if val[n] in res1: pass else: Errores.insertar( Nodo_Error('22023', 'invalid_parameter_value', self.fila, self.columna)) return '22023 : invalid_parameter_value' respuesta = jm.insert(bd, self.table_id, val) if respuesta == 2: # noexisteDB Errores.insertar( Nodo_Error('08003', 'connection_does_not_exist', self.fila, self.columna)) return '08003: ' + str(bd) + ' connection_does_not_exist\n' elif respuesta == 3: # noexisteTB Errores.insertar( Nodo_Error('42P01', 'undefined_table', self.fila, self.columna)) return '42P01: ' + str( self.table_id) + ' undefined_table \n' elif respuesta == 5: # noColDiferente Errores.insertar( Nodo_Error('HV008', 'fdw_invalid_column_number', self.fila, self.columna)) return 'HV008: fdw_invalid_column_number \n' elif respuesta == 4: # Pk_duplicada Errores.insertar( Nodo_Error('42710', 'duplicate_object', self.fila, self.columna)) return '42710: duplicate_object \n' elif respuesta == 1: # error Errores.insertar( Nodo_Error('XX000', 'internal_error', self.fila, self.columna)) return 'XX000: internal_error \n' else: for n, s in enumerate(TiposCol): k = list(s.values()) r = nombreCol[n] #nombrecol a = k[0] #tipo dato b = k[1] #size #tts.TabladeSimbolos.insertar(r,a,b,self.table_id,self.fila,self.columna,'Insert') return 'Se ingresaron los registros exitosamente \n' else: Errores.insertar( Nodo_Error('HV008', 'fdw_invalid_column_number', self.fila, self.columna)) return 'HV008: fdw_invalid_column_number \n'