コード例 #1
0
ファイル: update.py プロジェクト: sandymerida/tytus
 def execute(self, environment):
     try:
         # Verificamos que no pueden venir mas de 1 tabla en el clausula FROM
         if len(self.fromcl.tables) > 1:
             instruction.semanticErrors.append(
                 ["Error sintactico cerco e en ','", self.row])
             instruction.syntaxPostgreSQL.append(
                 "Error: 42601: Error sintactico cerca de , en la linea " +
                 str(self.row))
             return "Error: syntax error at or near ','"
         newEnv = Environment(environment, instruction.dbtemp)
         instruction.envVariables.append(newEnv)
         self.fromcl.execute(newEnv)
         value = [newEnv.dataFrame[p] for p in newEnv.dataFrame]
         labels = [p for p in newEnv.dataFrame]
         for i in range(len(labels)):
             newEnv.dataFrame[labels[i]] = value[i]
         if self.wherecl == None:
             w2 = newEnv.dataFrame.filter(labels)
         else:
             wh = self.wherecl.execute(newEnv)
             w2 = wh.filter(labels)
         # Si la clausula WHERE devuelve un dataframe vacio
         if w2.empty:
             return "Operacion UPDATE completada"
         # Logica para realizar el update
         table = self.fromcl.tables[0].name
         pk = Struct.extractPKIndexColumns(instruction.dbtemp, table)
         # Se obtienen las parametros de las llaves primarias para proceder a eliminar
         rows = []
         if pk:
             for row in w2.values:
                 rows.append([row[p] for p in pk])
         else:
             rows.append([i for i in w2.index])
         print(rows)
         # Obtenemos las variables a cambiar su valor
         ids = [p.id for p in self.values]
         values = [p.execute(newEnv).value for p in self.values]
         ids = Struct.getListIndex(instruction.dbtemp, table, ids)
         if len(ids) != len(values):
             return "Error: Columnas no encontradas"
         temp = {}
         for i in range(len(ids)):
             temp[ids[i]] = values[i]
         print(temp, rows)
         # TODO: La funcion del STORAGE esta bugueada
         bug = False
         for row in rows:
             result = jsonMode.update(instruction.dbtemp, table, temp, rows)
             if result != 0:
                 bug = True
                 break
         if bug:
             return ["Error: Funcion UPDATE del Storage", temp, rows]
         return "Operacion UPDATE completada"
     except:
         instruction.syntaxPostgreSQL.append(
             "Error: P0001: Error en la instruccion UPDATE")
コード例 #2
0
 def execute(self, environment):
     # insert = [posiblesErrores,noColumnas]
     insert = Struct.insertTable(instruction.dbtemp, self.name,
                                 self.columns, self.inherits)
     error = insert[0]
     nCol = insert[1]
     if not error:
         error = Checker.checkValue(instruction.dbtemp, self.name)
     """
     Result
     0: insert
     1: error
     2: not found database
     3: exists table
     """
     if not error:
         result = jsonMode.createTable(instruction.dbtemp, self.name, nCol)
         result = avlMode.createTable(instruction.dbtemp, self.name, nCol)
         if result == 0:
             pass
         elif result == 1:
             instruction.syntaxPostgreSQL.append(
                 "Error: XX000: Error interno")
             return "Error: No se puede crear la tabla: " + self.name
         elif result == 2:
             instruction.semanticErrors.append("La base de datos " +
                                               instruction.dbtemp +
                                               " no existe")
             instruction.syntaxPostgreSQL.append(
                 "Error: 3F000: base de datos" + instruction.dbtemp +
                 " no existe")
             return "Error: Base de datos no encontrada: " + instruction.dbtemp
         elif result == 3 and self.exists:
             instruction.semanticErrors.append(
                 ["La tabla " + str(self.name) + " ya existe", self.row])
             instruction.syntaxPostgreSQL.append(
                 "Error: 42P07: La tabla  " + str(self.name) + " ya existe")
             return "La tabla ya existe en la base de datos"
         else:
             instruction.semanticErrors.append(
                 ["La tabla " + str(self.name) + " ya existe", self.row])
             instruction.syntaxPostgreSQL.append(
                 "Error: 42P07: tabla duplicada")
             return "Error: ya existe la tabla " + self.name
         pk = Struct.extractPKIndexColumns(instruction.dbtemp, self.name)
         addPK = 0
         if pk:
             addPK2 = jsonMode.alterAddPK(instruction.dbtemp, self.name, pk)
             addPK = avlMode.alterAddPK(instruction.dbtemp, self.name, pk)
         if addPK != 0:
             instruction.syntaxPostgreSQL.append(
                 "Error: 23505: Error en llaves primarias de la instruccion CREATE TABLE de la tabla "
                 + str(self.name))
         return "Tabla " + self.name + " creada"
     else:
         Struct.dropTable(instruction.dbtemp, self.name)
         return error