def alterDropColumn(self, database, table, columnNumber): if self.searchDB(database): if self.searchTB(database, table): if columnNumber >= 0 and columnNumber < self.dicDB[database][table][1]: if self.dicDB[database][table][1] > 1: try: columnNumber = int(columnNumber) if self.dicDB[database][table][2] != None: if columnNumber not in self.dicDB[database][table][2]: self.dicDB[database][table][1] -= 1 self.dicDB[database][table][0].eliminarValor(columnNumber) pk = [] for i in self.dicDB[database][table][2]: if i < columnNumber: pk.append(i) else: pk.append(i-1) self.dicDB[database][table][2] = pk serializar.commit(self.dicDB[database][table][0], database+"-"+table+"-B") return 0 return 4 else: self.dicDB[database][table][1] -= 1 self.dicDB[database][table][0].eliminarValor(columnNumber) serializar.commit(self.dicDB[database][table][0], database+"-"+table+"-B") return 0 except: return 1 return 4 return 5 return 3 return 2
def alterAddPK(self, database, table, columns): try: for i in columns: int(i) table.lower() except: return 1 if self.searchDB(database): if self.searchTB(database, table): try: range = True for i in columns: if range: if i >= self.dicDB[database][table][1]: range = False if range: if not self.dicDB[database][table][2]: if self.verifyPk(database, table, columns): self.dicDB[database][table][2] = columns self.updateTree(database, table) serializar.commit( self.dicDB[database][table][0], database + "-" + table + "-B") return 0 return 4 return 4 return 5 except: return 1 return 3 return 2
def alterAddColumn(database: str, table: str, default: any) -> int: try: b.dicDB[database][table][0] = serializar.rollback(database+"-"+table+"-B") except: pass r = b.alterAddColumn(database, table, default) try: b.dicDB[database][table][0] = bt.arbolB(b.grade) serializar.commit(b, "BDD") except: pass return r
def alterDropPK(database: str, table: str) -> int: try: b.dicDB[database][table][0] = serializar.rollback(database+"-"+table+"-B") except: pass r = b.alterDropPK(database, table) try: b.dicDB[database][table][0] = bt.arbolB(b.grade) serializar.commit(b, "BDD") except: pass return r
def delete(database: str, table: str, columns: list) -> int: try: b.dicDB[database][table][0] = serializar.rollback(database+"-"+table+"-B") except: pass r = b.delete(database, table, columns) try: serializar.commit(b.dicDB[database][table][0], database+"-"+table+"-B") b.dicDB[database][table][0] = bt.arbolB(b.grade) serializar.commit(b, "BDD") except: pass return r
def loadCSV(file: str, database: str, table: str) -> list: try: b.dicDB[database][table][0] = serializar.rollback(database+"-"+table+"-B") except: pass r = b.loadCSV(file, database, table) try: serializar.commit(b.dicDB[database][table][0], database+"-"+table+"-B") b.dicDB[database][table][0] = bt.arbolB(b.grade) serializar.commit(b, "BDD") except: pass return r
def insert(database: str, table: str, register: list) -> int: try: b.dicDB[database][table][0] = serializar.rollback(database+"-"+table+"-B") except: pass r = b.insert(database, table, register) try: serializar.commit(b.dicDB[database][table][0], database+"-"+table+"-B") b.dicDB[database][table][0] = bt.arbolB(b.grade) serializar.commit(b, "BDD") except: pass return r
def alterAddColumn(self, database, table, default): if self.identify(database) and self.identify(table): if self.searchDB(database): if self.searchTB(database, table): try: self.dicDB[database][table][1] += 1 self.dicDB[database][table][0].agregarValor(default) serializar.commit(self.dicDB[database][table][0], database+"-"+table+"-B") return 0 except: return 1 return 3 return 2 return 1
def update(self, database, table, register, columns): if self.searchDB(database): if self.searchTB(database, table): try: columns[0] = columns[0] if self.dicDB[database][table][2] != None: pk = "" for i in columns: pk += str(i) + "_" pk = pk[:-1] if pk in self.dicDB[database][table][0].Keys(): tupla = self.extractRow(database, table, columns) for key, value in register.items(): tupla[key] = value self.dicDB[database][table][0].update(tupla, pk) self.updateTree(database, table) serializar.commit(self.dicDB[database][table][0], database + "-" + table + "-B") return 0 return 4 else: pk = "" for i in columns: pk += str(i) + "_" pk = pk[:-1] if pk in self.dicDB[database][table][0].Keys(): tupla = self.extractRow(database, table, columns) for key, value in register.items(): tupla[key] = value self.dicDB[database][table][0].update(tupla, pk) self.updateTree(database, table) serializar.commit(self.dicDB[database][table][0], database + "-" + table + "-B") return 0 return 4 except: return 1 return 3 return 2
def alterTable(database: str, tableOld: str, tableNew: str) -> int: r = b.alterTable(database, tableOld, tableNew) serializar.commit(b, "BDD") return r
def createTable(database: str, table: str, numberColumns: int) -> int: r = b.createTable(database, table, numberColumns) serializar.commit(b, "BDD") return r
def dropDatabase(database: str) -> int: r = b.dropDatabase(database) serializar.commit(b, "BDD") return r
def alterDatabase(databaseOld, databaseNew) -> int: r = b.alterDatabase(databaseOld, databaseNew) serializar.commit(b, "BDD") return r
def createDatabase(database: str) -> int: r = b.createDatabase(database) serializar.commit(b, "BDD") return r
def dropTable(database: str, table: str) -> int: r = b.dropTable(database, table) serializar.commit(b, "BDD") return r
# File: B Mode Package # License: Released under MIT License # Notice: Copyright (c) 2020 TytusDB Team from team17 import DataBase as db from team17 import Serializable as serializar from team17 import Interfaz as interfaz from team17 import Estructura_ArbolB as bt b = db.DB() try: b = serializar.rollback("BDD") except: serializar.commit(b, "BDD") #---------------------FUNCIONES BASES DE DATOS----------------------# def createDatabase(database: str) -> int: r = b.createDatabase(database) serializar.commit(b, "BDD") return r def showDatabases() -> list: return b.showDatabases() def alterDatabase(databaseOld, databaseNew) -> int: r = b.alterDatabase(databaseOld, databaseNew) serializar.commit(b, "BDD") return r