Ejemplo n.º 1
0
def alterDropPK(database: str, table: str) -> int:
    dbs = databases.find_all(database)
    if dbs == []:
        return 2
    for db in dbs:
        if db.mode == "avl":
            result = avlMode.alterDropPK(database, table)
        elif db.mode == "b":
            result = BMode.alterDropPK(database, table)
        elif db.mode == "bplus":
            result = BPlusMode.alterDropPK(database, table)
        elif db.mode == "dict":
            result = DictMode.alterDropPK(database, table)
        elif db.mode == "isam":
            result = ISAMMode.alterDropPK(database, table)
        elif db.mode == "json":
            result = jsonMode.alterDropPK(database, table)
        elif db.mode == "hash":
            result = HashMode.alterDropPK(database, table)
        if result != 3:
            if result == 0:
                db.tables.search(table).pk = []
                for x in range(5):
                    try:
                        Serializable.commit(databases, "lista_bases_de_datos")
                        return result
                    except:
                        break
                return 1
            break
    return result
Ejemplo n.º 2
0
def alterDropPK(database: str, table: str) -> int:
    try:
        retorno = 1
        db = __buscarLlaveBaseDato(database)
        if db is not None:
            modoDB = db[0]
            tablas = db[2]
            if tablas:
                if tablas.get(table) is not None:
                    modoDB = tablas[table]
            if modoDB == "avl":
                retorno = avl.alterDropPK(database, table)
            elif modoDB == "b":
                retorno = b.alterDropPK(database, table)
            elif modoDB == "bplus":
                retorno = bPlus.alterDropPK(database, table)
            elif modoDB == "dict":
                retorno = dic.alterDropPK(database, table)
            elif modoDB == "isam":
                retorno = isam.alterDropPK(database, table)
            elif modoDB == "json":
                retorno = json.alterDropPK(database, table)
            elif modoDB == "hash":
                retorno = hash.alterDropPK(database, table)
            if retorno == 0:
                pk = generalDict[database][3]
                del pk[table]
                generalDict[database][3] = pk
                ser("data/info/datos.bin", generalDict)
            return retorno
        else:
            return 2

    except Exception:
        return 1
Ejemplo n.º 3
0
def alterDropPK(database: str, table: str) -> int:
    """Deletes PKs of a table in a database

        Parameters:\n
            database (str): name of the database
            table (str): name of the table

        Returns:\n
            0: successful operation
            1: an error ocurred
            2: non-existent database
            3: non-existent table
            4: non-existent PK
    """

    bd = _database(database)

    if bd:

        tb = _table(database, table)

        if tb:

            mode = tb["modo"]

            val = -1

            if mode == "avl":
                val = avl.alterDropPK(database, table)

            elif mode == "b":
                val = b.alterDropPK(database, table)

            elif mode == "bplus":
                val = bplus.alterDropPK(database, table)

            elif mode == "hash":
                val = hash.alterDropPK(database, table)

            elif mode == "isam":
                val = isam.alterDropPK(database, table)

            elif mode == "json":
                val = json.alterDropPK(database, table)

            elif mode == "dict":
                val = dict.alterDropPK(database, table)

            if val == 0:
                _table(database, table)["pk"]=[]
                _Guardar()

            return val

        else:
            return 3

    else:
        return 2