Exemple #1
0
def alterAddPK(database: str, table: str, columns: list) -> int:
    try:
        if not database.isidentifier() \
        or not table.isidentifier() \
        or not isinstance(columns, list):
            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.alterAddPK(database, table, columns)
        elif mode == "b":
            estado = b.alterAddPK(database, table, columns)
        elif mode == "bplus":
            estado = bplus.alterAddPK(database, table, columns)
        elif mode == "hash":
            estado = ha.alterAddPK(database, table, columns)
        elif mode == "isam":
            estado = isam.alterAddPK(database, table, columns)
        elif mode == "json":
            estado = j.alterAddPK(database, table, columns)
        elif mode == "dict":
            estado = d.alterAddPK(database, table, columns)

        if estado == 0:
            if deserializadoActivado is False:
                # 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"] = columns
                                break

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

        return estado
    except:
        return 1
Exemple #2
0
def alterAddPK(database, table, columns):
    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.alterAddPK(database, table, columns)
        return value_return
    except:
        return 1
Exemple #3
0
 def createTable(self):
 
     if self.modo == "avl":
         avl.createTable(self.database, self.table, self.columnas)
         avl.alterAddPK(self.database, self.table, [0])
     elif self.modo == "b":
         b.createTable(self.database, self.table, self.columnas)
         b.alterAddPK(self.database, self.table, [0])
     elif self.modo == "bplus":
         bplus.createTable(self.database, self.table, self.columnas)
         bplus.alterAddPK(self.database, self.table, [0])
     elif self.modo == "hash":
         ha.createTable(self.database, self.table, self.columnas)
         ha.alterAddPK(self.database, self.table, [0])
     elif self.modo == "isam":
         isam.createTable(self.database, self.table, self.columnas)
         isam.alterAddPK(self.database, self.table, [0])
     elif self.modo == "json":
         j.createTable(self.database, self.table, self.columnas)
         j.alterAddPK(self.database, self.table, [0])
     elif self.modo == "dict":
         d.createTable(self.database, self.table, self.columnas)
         d.alterAddPK(self.database, self.table, [0])