Exemple #1
0
 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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
 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
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
def extractTable(database: str, table: str) -> list:
    try:
        b.dicDB[database][table][0] = serializar.rollback(database + "-" +
                                                          table + "-B")
    except:
        pass
    return b.extractTable(database, table)
Exemple #9
0
def extractRangeTable(database: str, table: str, columnNumber: int, lower: any,
                      upper: any) -> list:
    try:
        b.dicDB[database][table][0] = serializar.rollback(database + "-" +
                                                          table + "-B")
    except:
        pass
    return b.extractRangeTable(database, table, columnNumber, lower, upper)
Exemple #10
0
 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
Exemple #11
0
 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
Exemple #12
0
def createTable(database: str, table: str, numberColumns: int) -> int:
    r = b.createTable(database, table, numberColumns)
    serializar.commit(b, "BDD")
    return r
Exemple #13
0
def alterTable(database: str, tableOld: str, tableNew: str) -> int:
    r = b.alterTable(database, tableOld, tableNew)
    serializar.commit(b, "BDD")
    return r
Exemple #14
0
def alterDatabase(databaseOld, databaseNew) -> int:
    r = b.alterDatabase(databaseOld, databaseNew)
    serializar.commit(b, "BDD")
    return r
Exemple #15
0
def createDatabase(database: str) -> int:
    r = b.createDatabase(database)
    serializar.commit(b, "BDD")
    return r
Exemple #16
0
def dropTable(database: str, table: str) -> int:
    r = b.dropTable(database, table)
    serializar.commit(b, "BDD")
    return r
Exemple #17
0
def dropDatabase(database: str) -> int:
    r = b.dropDatabase(database)
    serializar.commit(b, "BDD")
    return r
Exemple #18
0
# File:     B Mode Package
# License:  Released under MIT License
# Notice:   Copyright (c) 2020 TytusDB Team

from storage.BTree import DataBase as db
from storage.BTree import Serializable as serializar
from storage.BTree 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")