예제 #1
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def renameColumn(table, name, newName):
    for col in table["columns"]:
        if col["name"] == name:
            col["name"] = newName
            File.exportFile(Databases, "Databases")
            return
    Error.append("No se encontro la colunma")
예제 #2
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def alterColumnsTable(dbName, tName, params):
    table = extractTable(dbName, tName)
    if table == 1 or table == 0:
        return ListError()
    nInit = len(table["columns"])
    for p in params:
        if p[0] == "ADD":
            p.remove("ADD")
            nCol = insertColumns(dbName, table, p)
            if nCol - nInit == 1:
                jsonMode.alterAddColumn(dbName, tName, None)
                nInit += 1
        elif p[0] == "RENAME":

            renameColumn(table, p[1][0], p[1][1])
        elif p[0] == "DROP":
            if p[1][0] == "COLUMN":
                alterDrop(table, p[1][1])
            else:
                dropConstraint(table, p[1][1])
                File.exportFile(Databases, "Databases")
        else:
            type_ = p[1][0]
            col = p[1][1]
            value = p[1][2]
            if type_ == "SET":
                setColumn(table, col, value)
            else:
                alterType(table, col, value)
    return ListError()
예제 #3
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def alterDatabaseRename(databaseOld, databaseNew):
    for data in Databases:
        if data["name"] == databaseOld:
            data["name"] = databaseNew
            File.exportFile(Databases, "Databases")
            return
    return
예제 #4
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def createDatabase(name, mode, owner):
    database = {}
    database["name"] = name
    database["mode"] = mode
    database["owner"] = owner
    database["tables"] = []
    Databases.append(database)
    File.exportFile(Databases, "Databases")
예제 #5
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
예제 #6
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def insertColumns(dbName, table, columns):
    for column in columns:
        if column[0]:
            constraint(table, column, dbName)
        else:
            table["columns"].append(getCol(column))

    File.exportFile(Databases, "Databases")

    return len(table["columns"])
예제 #7
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def createType(exist, name, list_):
    if existType(name):
        if exist:
            return "Type no insertado"
        else:
            return "Error: ya existe un type con el nombre " + name

    Types[name] = list_
    File.exportFile(Types, "Types")
    return None
예제 #8
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def alterDatabaseOwner(database, ownerNew):
    if ownerNew == "CURRENT_USER" or ownerNew == "SESSION_USER":
        ownerNew = "root"

    for data in Databases:
        if data["name"] == database:
            data["owner"] = ownerNew
            File.exportFile(Databases, "Databases")
            return 0
    return 1
예제 #9
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def dropDatabase(name):
    element = {}
    for data in Databases:
        if data["name"] == name:
            element = data
            break
    if element != {}:
        Databases.remove(element)
        File.exportFile(Databases, "Databases")
        return "Drop database"
    return "Database not found"
예제 #10
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def dropTable(dbName, tableName):
    tbl = {}
    for db in Databases:
        if db["name"] == dbName:
            for table in db["tables"]:
                if table["name"] == tableName:
                    tbl = table
                    break
            if tbl != {}:
                db["tables"].remove(tbl)
                File.exportFile(Databases, "Databases")
            break
예제 #11
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def alterDrop(table, colName):
    clm = {}
    for col in table["columns"]:
        if col["name"] == colName:
            clm = col
            break

    if clm != {}:
        table["columns"].remove(clm)
        File.exportFile(Databases, "Databases")
        return

    Error.append("No se encontró la columna")
예제 #12
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def setColumn(table, name, value):
    type_ = value[0]
    value = value[1]
    for column in table["columns"]:

        if column["name"] == name:
            if type_ == "NULL":
                column["NN"] = value
            if type_ == "DEFAULT":
                column["Default"] = [value.value, value.type.value]
            else:
                Error.append("Set desconocido")
            break

    File.exportFile(Databases, "Databases")
예제 #13
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
예제 #14
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def createTable(dbName, tableName, inherits):
    table = {}
    table["name"] = tableName
    table["inherits"] = inherits

    columns = getInherits(dbName, inherits)
    if columns == 0 or columns == 1:
        return

    table["columns"] = columns

    for db in Databases:
        if db["name"] == dbName:
            db["tables"].append(table)
            break

    File.exportFile(Databases, "Databases")
예제 #15
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def alterType(table, name, value):
    for column in table["columns"]:
        if column["name"] == name:
            if column["type"] == "TEXT":
                Error.append("No se puede modificar el type")
            else:
                if column["size"] == None or value[1][0] == None:
                    Error.append("No se puede modificar el type")
                else:
                    if value[1][0] < column["size"]:
                        Error.append("No se puede modificar el type")
                    else:
                        column["size"] = value[1][0]
                        column["type"] = value[0]
            break

    File.exportFile(Databases, "Databases")
예제 #16
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"
예제 #17
0
파일: Struct.py 프로젝트: ChinJavier/tytus
def save():
    File.exportFile(Databases, "Databases")