Beispiel #1
0
def alterTable(database: str, tableOld: str, tableNew: str) -> int:
    try:
        retorno = 1
        db = __buscarLlaveBaseDato(database)
        if db is not None:
            modoDB = db[0]
            tablas = db[2]
            if tablas:
                if tablas.get(tableOld) is not None:
                    modoDB = tablas[tableOld]
            if modoDB == "avl":
                retorno = avl.alterTable(database, tableOld, tableNew)
            elif modoDB == "b":
                retorno = b.alterTable(database, tableOld, tableNew)
            elif modoDB == "bplus":
                retorno = bPlus.alterTable(database, tableOld, tableNew)
            elif modoDB == "dict":
                retorno = dic.alterTable(database, tableOld, tableNew)
            elif modoDB == "isam":
                retorno = isam.alterTable(database, tableOld, tableNew)
            elif modoDB == "json":
                retorno = json.alterTable(database, tableOld, tableNew)
            elif modoDB == "hash":
                retorno = hash.alterTable(database, tableOld, tableNew)
            return retorno
        else:
            return 2

    except Exception:
        return 1
Beispiel #2
0
def alterTable(database, tableOld, tableNew):
    dbs = databases.find_all(database)
    if dbs == []:
        return 2
    for db in dbs:
        if db.mode == "avl":
            result = avlMode.alterTable(database, tableOld, tableNew)
        elif db.mode == "b":
            result = BMode.alterTable(database, tableOld, tableNew)
        elif db.mode == "bplus":
            result = BPlusMode.alterTable(database, tableOld, tableNew)
        elif db.mode == "dict":
            result = DictMode.alterTable(database, tableOld, tableNew)
        elif db.mode == "isam":
            result = ISAMMode.alterTable(database, tableOld, tableNew)
        elif db.mode == "json":
            result = jsonMode.alterTable(database, tableOld, tableNew)
        elif db.mode == "hash":
            result = HashMode.alterTable(database, tableOld, tableNew)
        if result != 3:
            if result == 0:
                db.tables.search(tableOld).name = tableNew
                for x in range(5):
                    try:
                        Serializable.commit(databases, "lista_bases_de_datos")
                        return result
                    except:
                        break
                return 1
            break
    return result
Beispiel #3
0
def alterTable(database: str, tableOld: str, tableNew: str) -> int:
    """Renames a table in a database

        Parameters:\n
            database (str): name of the database
            tableOld (str): name of the target table
            tableNew (str): new name of the table

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

    bd = _database(database)

    if bd:

        tb = _table(database, tableOld)

        if tb:

            mode = tb["modo"]

            val = -1

            if mode == "avl":
                val = avl.alterTable(database, tableOld, tableNew)

            elif mode == "b":
                val = b.alterTable(database, tableOld, tableNew)

            elif mode == "bplus":
                val = bplus.alterTable(database, tableOld, tableNew)

            elif mode == "hash":
                val = hash.alterTable(database, tableOld, tableNew)

            elif mode == "isam":
                val = isam.alterTable(database, tableOld, tableNew)

            elif mode == "json":
                val = json.alterTable(database, tableOld, tableNew)

            elif mode == "dict":
                val = dict.alterTable(database, tableOld, tableNew)

            if val == 0:
                _table(database, tableOld)["nombre"]=tableNew
                _Guardar()

            return val

        else:
            return 3

    else:
        return 2
Beispiel #4
0
def alterTable(database, old_table, new_table):
    ModeDB, indexDB = exist_Alter(database)
    if ModeDB:
        mode = ModeDB.get_mode()
        if mode.lower().strip() == "avl":
            return avl.alterTable(database, old_table, new_table)
        elif mode.lower().strip() == "b":
            return b.alterTable(database, old_table, new_table)
        elif mode.lower().strip() == "bPlus".lower():
            return bPlus.alterTable(database, old_table, new_table)
        elif mode.lower().strip() == "dict":
            return diccionario.alterTable(database, old_table, new_table)
        elif mode.lower().strip() == "hash":
            return hash.alterTable(database, old_table, new_table)
        elif mode.lower().strip() == "isam":
            return isam.alterTable(database, old_table, new_table)
        elif mode.lower().strip() == "json":
            return json.alterTable(database, old_table, new_table)