def createDatabase(database: str, mode: str, encoding: str) -> int: try: retorno = 3 if encoding in ["ascii", "iso-8859-1", "utf8"]: if __buscarLlaveBaseDato(database) is None: if mode == "avl": retorno = avl.createDatabase(database) elif mode == "b": retorno = b.createDatabase(database) elif mode == "bplus": retorno = bPlus.createDatabase(database) elif mode == "dict": retorno = dic.createDatabase(database) elif mode == "isam": retorno = isam.createDatabase(database) elif mode == "json": retorno = json.createDatabase(database) elif mode == "hash": retorno = hash.createDatabase(database) else: retorno = 3 if retorno == 0: generalDict.setdefault(database, [mode, encoding, {}, {}]) ser("data/info/datos.bin", generalDict) return retorno else: return 2 else: return 4 except Exception: return 1
def __createDatabase(database: str, mode: str, encoding: str) -> int: try: retorno = 3 if encoding in ["ascii", "iso-8859-1", "utf8"]: if __buscarLlaveBaseDato(database) is not None: if mode == "avl": retorno = avl.createDatabase(database) elif mode == "b": retorno = b.createDatabase(database) elif mode == "bplus": retorno = bPlus.createDatabase(database) elif mode == "dict": retorno = dic.createDatabase(database) elif mode == "isam": retorno = isam.createDatabase(database) elif mode == "json": retorno = json.createDatabase(database) elif mode == "hash": retorno = hash.createDatabase(database) else: retorno = 3 return retorno else: return 2 else: return 4 except Exception: return 1
def createdatabase(db, modo, cod): if not modo in modos: return 3 if not cod in encoding: return 4 if buscar(db) == None: if modo == "avl": tmp = avl.createDatabase(db) elif modo == "b": tmp = b.createDatabase(db) elif modo == "bplus": tmp = bplus.createDatabase(db) elif modo == "hash": tmp = hash.createDatabase(db) elif modo == "isam": tmp = isam.createDatabase(db) elif modo == "json": tmp = json.createDatabase(db) elif modo == "dict": tmp = dict.createDatabase(db) else: return 2 if tmp == 0: lista_db.append([db, modo, cod]) return 0 else: return 1
def createDatabase(database: str, mode: str, encoding: str): if verify_string(database): if exist(database): return 2 if encoding.lower().strip() is "ascii" or encoding.lower().strip() is "iso-8859-1" \ or encoding.lower().strip() is "utf8": status = -1 if mode.lower().strip() is "avl": status = avl.createDatabase(database) elif mode.lower().strip() is "b": status = b.createDatabase(database) elif mode.lower().strip() is "bplus": status = bPlus.createDatabase(database) elif mode.lower().strip() is "dict": status = diccionario.createDatabase(database) elif mode.lower().strip() is "isam": status = isam.createDatabase(database) elif mode.lower().strip() is "json": status = json.createDatabase(database) elif mode.lower().strip() is "hash": status = hash.createDatabase(database) else: return 3 if status == 0: save_mode(database, mode, encoding) return status else: return 4 else: return 1
def chooseMode(mode, database): if mode == 'avl': if avl.createDatabase(database) == 0: avlList.append(database) return 0 else: return avl.createDatabase(database) elif mode == 'b': if b.createDatabase(database) == 0: bList.append(database) return 0 else: return b.createDatabase(database) elif mode == 'bplus': if bplus.createDatabase(database) == 0: bplusList.append(database) return 0 else: return bplus.createDatabase(database) elif mode == 'dict': if DM.createDatabase(database) == 0: dictList.append(database) return 0 else: return DM.createDatabase(database) elif mode == 'isam': if isam.createDatabase(database) == 0: isamList.append(database) return 0 else: return isam.createDatabase(database) elif mode == 'json': if j.createDatabase(database) == 0: jsonList.append(database) return 0 else: return j.createDatabase(database) elif mode == 'hash': if Hash.createDatabase(database) == 0: hashList.append(database) return 0 else: return Hash.createDatabase(database)
def createDatabase(database: str, mode: str, encoding: str) -> int: """Creates a database Parameters:\n database (str): name of the database Returns:\n 0: successful operation 1: an error ocurred 2: database name occupied """ if not _Buscar(database): if encoding not in ["utf8", "ascii", "iso-8859-1"]: return 4 if mode == "avl": val = avl.createDatabase(database) elif mode == "b": val = b.createDatabase(database) elif mode == "bplus": val = bplus.createDatabase(database) elif mode == "hash": val = hash.createDatabase(database) elif mode == "isam": val = isam.createDatabase(database) elif mode == "json": val = json.createDatabase(database) elif mode == "dict": val = dict.createDatabase(database) else: return 3 if val == 0: lista_general.append([database, mode, encoding]) serealizar.commit(lista_general, "data", _main_path) return val else: return 2
def __create_database_sp(database: str, mode: str, encoding: str) -> int: if encoding not in VALID_ENCODING: return 4 dbs = databases.find_all(database) if dbs != None: for db in dbs: if db.name == database and db.mode == mode: # Ya existe esta base de datos alternativa return 0 if mode == "avl": code = avlMode.createDatabase(database) elif mode == "b": code = BMode.createDatabase(database) elif mode == "bplus": code = BPlusMode.createDatabase(database) elif mode == "dict": code = DictMode.createDatabase(database) elif mode == "isam": code = ISAMMode.createDatabase(database) elif mode == "json": code = jsonMode.createDatabase(database) elif mode == "hash": code = HashMode.createDatabase(database) else: return 3 if code == 0: databases.create(database, mode, encoding) try: for i in range(5): try: Serializable.commit(databases, "lista_bases_de_datos") except: continue except: code_drop = dropDatabase(database) if code_drop == 0: databases.delete(database) return 1 else: for i in range(4): code_drop = dropDatabase(database) if code_drop == 0: databases.delete(database) break return 1 return code
def _createDatabase(database, mode, encoding) -> int: """Creates a database Parameters:\n database (str): name of the database mode (str): mode of the database encoding (str): encoding of the database Returns:\n 0: successful operation 1: an error ocurred 2: database name occupied 3: non-valid mode 4: non-valid encoding """ if encoding not in ["utf8", "ascii", "iso-8859-1"]: return 4 if mode == "avl": val = avl.createDatabase(database) elif mode == "b": val = b.createDatabase(database) elif mode == "bplus": val = bplus.createDatabase(database) elif mode == "hash": val = hash.createDatabase(database) elif mode == "isam": val = isam.createDatabase(database) elif mode == "json": val = json.createDatabase(database) elif mode == "dict": val = dict.createDatabase(database) else: return 3 return val
def createDatabase(database: str, mode: str, encoding: str) -> int: if encoding not in VALID_ENCODING: return 4 if databases.search(database) != None: return 2 if mode == "avl": code = avlMode.createDatabase(database) elif mode == "b": code = BMode.createDatabase(database) elif mode == "bplus": code = BPlusMode.createDatabase(database) elif mode == "dict": code = DictMode.createDatabase(database) elif mode == "isam": code = ISAMMode.createDatabase(database) elif mode == "json": code = jsonMode.createDatabase(database) elif mode == "hash": code = HashMode.createDatabase(database) else: return 3 if code == 0: databases.create(database, mode, encoding) databases.search(database).main_db = True try: for i in range(5): try: Serializable.commit(databases, "lista_bases_de_datos") except: continue except: code_drop = dropDatabase(database) if code_drop == 0: databases.delete(database) return 1 else: for i in range(4): code_drop = dropDatabase(database) if code_drop == 0: databases.delete(database) break return 1 return code
def alterDatabaseMode(database: str, mode: str) -> int: try: valor = 1 db = __buscarLlaveBaseDato(database) retorno = 1 if db is not None: modeOld = db[0] tablas = showTables(database) codificacion = db[1] if mode == "avl": retorno = avl.createDatabase(database) elif mode == "b": retorno = b.createDatabase(database) elif mode == "bplus": retorno = bPlus.createDatabase(database) elif mode == "dict": retorno = dic.createDatabase(database) elif mode == "isam": retorno = isam.createDatabase(database) elif mode == "json": retorno = json.createDatabase(database) elif mode == "hash": retorno = hash.createDatabase(database) else: retorno = 4 if retorno == 0 or retorno == 2: valor = __insertarDatosTablas(tablas, mode, modeOld, database, codificacion) retorno = valor dicc = db[2] if valor == 0: dropDatabase(database) db[0] = mode db[2] = {} generalDict[database] = db ser("data/info/datos.bin", generalDict) return retorno else: return 2 except Exception: return 1