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):
    if searchInMode(tableOld) != None:
        currentMode = searchInMode(tableOld)
        if currentMode == 'avl':
            avlList.append(tableNew)
            return avl.alterTable(database, tableOld, tableNew)
        elif currentMode == 'b':
            bList.append(tableNew)
            return b.alterTable(database, tableOld, tableNew)
        elif currentMode == 'bplus':
            bplusList.append(tableNew)
            return bplus.alterTable(database, tableOld, tableNew)
        elif currentMode == 'dict':
            dictList.append(tableNew)
            return DM.alterTable(database, tableOld, tableNew)
        elif currentMode == 'isam':
            isamList.append(tableNew)
            return isam.alterTable(database, tableOld, tableNew)
        elif currentMode == 'json':
            jsonList.append(tableNew)
            return j.alterTable(database, tableOld, tableNew)
        elif currentMode == 'hash':
            hashList.append(tableNew)
            return Hash.alterTable(database, tableOld, tableNew)
    else:
        return 2
Beispiel #3
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 #4
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 #5
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)