예제 #1
0
def alterDropPK(database, table):
    try:
        dictionary = load('metadata')

        value_base = dictionary.get(database)
        if not value_base:
            return 2

        mode = dictionary.get(database)[0]
        j = checkMode(mode)
        value_return = j.alterDropPK(database, table)
        return value_return
    except:
        return 2
예제 #2
0
def alterDropPK(database: str, table: str) -> int:
    try:
        if not database.isidentifier() \
        or not table.isidentifier():
            raise Exception()
        
        dbBuscada = __getDatabase(database)
        if dbBuscada is False:
            return 2
        
        tbBuscada = __getTable(database, table)
        if tbBuscada is False:
            return 3
        
        mode = tbBuscada["mode"]

        estado = 1

        if mode == "avl":
            estado = avl.alterDropPK(database, table)
        elif mode == "b":
            estado = b.alterDropPK(database, table)
        elif mode == "bplus":
            estado = bplus.alterDropPK(database, table)
        elif mode == "hash":
            estado = ha.alterDropPK(database, table)
        elif mode == "isam":
            estado = isam.alterDropPK(database, table)
        elif mode == "json":
            estado = j.alterDropPK(database, table)
        elif mode == "dict":
            estado = d.alterDropPK(database, table)

        if estado == 0:
            # Pedir la lista de diccionarios de base de datos
            listaDB = __rollback("data")

            for db in listaDB:
                if db["nameDb"] == database:
                    for tb in db["tables"]:
                        if tb["nameTb"] == table:
                            tb["pk"] = []
                            break

            # Se guarda la lista de base de datos ya actualizada en el archivo data
            __commit(listaDB, "data")

        return estado
    except:
        return 1