Exemple #1
0
    def execute(self, environment):
        Struct.load()
        Index = File.importFile("Index")
        exists = Index.get(self.name)
        result = []
        if not exists:
            if self.exists:
                result.append("El INDEX : " + self.name + " no existe")
            else:
                result.append("Error: El INDEX : " + self.name + " no existe")
            return result

        if not self.id:
            exists = Index.get(self.newName)
            if not exists:
                Index[self.newName] = Index.pop(self.name)
                result.append("Se cambio el nombre del INDEX : " + self.name +
                              " a " + self.newName)
            else:
                result.append("Error: El INDEX : " + self.newName +
                              " ya existe")
        else:
            column = self.newName
            index = Index[self.name]
            for c in index["Columns"]:
                if c["Name"] == column:
                    if type(self.id) == int:
                        table = index["Table"]
                        columns = Struct.extractColumns(
                            instruction.dbtemp, table)
                        if columns:
                            if self.id > len(columns):
                                result.append("Error fatal: INDEX " +
                                              self.name +
                                              "numero de columna invalido")
                            else:
                                col = columns[self.id - 1].name
                                c["Name"] = col
                                result.append("INDEX : " + self.name +
                                              " cambio la columna " + column +
                                              " por " + col)
                        else:
                            result.append("Error fatal: INDEX " + self.name)
                    else:
                        c["Name"] = self.id
                        result.append("INDEX : " + self.name +
                                      " cambio la columna " + column +
                                      " por " + self.id)

                    Index[self.name] = index
                    break
        if result == []:
            result.append("Error fatal: INDEX " + self.name +
                          " columna invalida : " + self.newName)
        File.exportFile(Index, "Index")
        return result
Exemple #2
0
def indexReport():
    index = File.importFile("Index")
    enc = [["Nombre", "Tabla", "Unico", "Metodo", "Columnas"]]
    filas = []
    for (name, Index) in index.items():
        columns = ""
        for column in Index["Columns"]:
            columns += (", " + column["Name"] + " " + column["Order"] + " " +
                        column["Nulls"])
        filas.append([
            name, Index["Table"], Index["Unique"], Index["Method"], columns[1:]
        ])
    enc.append(filas)
    return enc
Exemple #3
0
    def execute(self, environment):
        Index = File.importFile("Index")
        result = []
        for name in self.names:
            exists = Index.get(name)
            if not exists:
                if self.exists:
                    result.append("El INDEX : " + name + " no existe")
                else:
                    result.append("Error: El INDEX : " + name + " no existe")
            else:
                Index.pop(name)
                result.append("INDEX : " + name + " eliminado")

        File.exportFile(Index, "Index")
        return result
Exemple #4
0
    def execute(self, environment):
        Struct.load()
        name = self.idIndex
        if self.existIndex(name):
            return "Error: ya existe un index con el nombre " + name
        table = Struct.extractTable(instruction.dbtemp, self.idTable)
        if table == 1 or table == 0:
            return (
                "Error: no existe la tabla "
                + self.idTable
                + " en la base de datos "
                + instruction.dbtemp
            )
        try:
            Index = File.importFile("Index")
            indexBody = {}
            indexBody["Table"] = self.idTable
            indexBody["Unique"] = self.unique
            indexBody["Method"] = self.usingMethod
            indexBody["Columns"] = []
            for c in self.optList:
                col = {}
                col["Name"] = c[0]
                col["Order"] = c[1]
                if c[2]:
                    nulls = c[2][0]
                    if c[2][1]:
                        nulls += " " + c[2][1]
                else:
                    if col["Order"] == "DESC":
                        nulls = "NULLS FIRST"
                    else:
                        nulls = "NULLS LAST"

                col["Nulls"] = nulls
                indexBody["Columns"].append(col)

            Index[name] = indexBody
            File.exportFile(Index, "Index")
            return "Index " + name + " creado"
        except:
            return "Error fatal"
Exemple #5
0
 def existIndex(self, name):
     Index = File.importFile("Index")
     exists = Index.get(name)
     if exists != None:
         return True
     return False
Exemple #6
0
def load():
    global Databases
    global Types
    Databases = File.importFile("Databases")
    Types = File.importFile("Types")