Ejemplo n.º 1
0
def dropTable(database, table) :
    try:
        dictionary = load('metadata')

        if dictionary.get(database) is None:
            return 2  # database doesn't exist

        mode = dictionary.get(database)[0]
        j = checkMode(mode)
        value_return = j.dropTable(database, table)

        if value_return == 0:
            dict_tables = dictionary.get(database)[2]
            dict_tables.pop(table)

            save(dictionary, 'metadata')
    except:
        return 1    
Ejemplo n.º 2
0
    def dropTable(self):

        estado = 1

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

        return estado
Ejemplo n.º 3
0
def dropTable(database: str, table: str) -> int:
    try:
        if not database.isidentifier() \
        or not table.isidentifier():
            raise Exception()

        baseDatos = __getDatabase(database)
        if baseDatos is False:
            return 2

        tabla = __getTable(database, table)
        if tabla is False:
            return 3

        # Fase2
        mode = tabla["mode"]

        res = 1

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

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

            #Se eliminan los registros de las estructuras correspondientes a
            #FK, indice unico, indice
            for db in listaDB:
                if db["nameDb"] == database:
                    for tb in db["tables"]:
                        if tb["nameTb"] == table:
                            tb["foreign_keys"].dropTable()
                            tb["unique_index"].dropTable()
                            tb["index"].dropTable()
                            break

            #Se elimina el diccionario correspondiente a la tabla del archivo data
            for db in listaDB:
                if db["nameDb"] == database:
                    db["tables"].remove(tabla)
                    break

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

        return res   
    except:
        return 1