def __createTable(database, table, numberColumns, mode): estado = 1 if mode == "avl": estado = avl.createTable(database, table, numberColumns) elif mode == "b": estado = b.createTable(database, table, numberColumns) elif mode == "bplus": estado = bplus.createTable(database, table, numberColumns) elif mode == "hash": estado = ha.createTable(database, table, numberColumns) elif mode == "isam": estado = isam.createTable(database, table, numberColumns) elif mode == "json": estado = j.createTable(database, table, numberColumns) elif mode == "dict": estado = d.createTable(database, table, numberColumns) if estado == 0: # Pedir la lista de diccionarios de base de datos listaDB = __rollback("data") for db in listaDB: if db["nameDb"] == database: db["tables"].append({ "nameTb": table, "mode": mode, "columns": numberColumns, "pk": [], "foreign_keys": indexM.indexManager(mode, database, table, 5, "fk"), "unique_index": indexM.indexManager(mode, database, table, 3, "un"), "index": indexM.indexManager(mode, database, table, 3, "in"), "registros": [], "registrosFk": [], "registrosUn": [], "registrosIn": [], "Bandera": False }) break # Se guarda la lista de base de datos ya actualizada en el archivo data __commit(listaDB, "data") return estado
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])
def createTable(database, table, numberColumns): 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.createTable(database, table, numberColumns) if value_return == 0: dict_tables = dictionary.get(database)[2] dict_tables[table] = [numberColumns, False] save(dictionary, 'metadata') return value_return except: return 1