Ejemplo n.º 1
0
    def alterDropColumn(self, database, table, columnnumber):
        try:
            search = CRUD_DataBase().searchDatabase(database)
            if search:
                search_table = self.extractTable(database, table)
                if search_table:
                    if columnnumber < search_table.numberColumns - 1:
                        if columnnumber == search_table.numberColumns:
                            return 4
                        else:
                            t = True
                            for n in search_table.PK:
                                if columnnumber == n:
                                    t = False
                            if t == True:
                                tmp = CRUD_DataBase().getRoot()
                                validation_aproved = self._alterDropColumns(database, table, columnnumber, tmp)
                                if validation_aproved:
                                    return 0
                                else:
                                    return 1
                            else:
                                return 4
                    else:
                        return 5

                else:
                    return 3
            else:
                return 2
        except:
            return 1
Ejemplo n.º 2
0
    def alterAddPK(self, database, table, columns):
        try:
            asd = []
            search = CRUD_DataBase().searchDatabase(database)
            if search:
                search_table = self.extractTable(database, table)
                if search_table is None:
                    return 3
                else:
                    large = search_table.numberColumns
                    # print(large)
                    # print(len(columns))
                    if len(columns) <= large:
                        tmp = CRUD_DataBase().getRoot()
                        if search_table.PK == asd:
                            validation_apoved = self._alterAddPK(database, table, columns, tmp)
                            if validation_apoved:
                                CRUD_DataBase().saveRoot(tmp)
                                return 0
                        else:
                            return 4

                    else:
                        return 5
            else:
                return 2
        except:
            return 1
Ejemplo n.º 3
0
 def guardar():
     name_database = txt.get()
     if name_database:
         txt.delete(0, END)
         crud = CRUD_DataBase()
         value = crud.createDatabase(name_database)
         if value == 0:
             messagebox.showinfo('', 'Operacion Exitosa')
         elif value == 2:
             messagebox.showinfo('', 'Base de Datos Existente')
         else:
             messagebox.showinfo('', 'Error en la Operacion')
Ejemplo n.º 4
0
 def eliminar():
     name_database = txt.get()
     if name_database:
         txt.delete(0, END)
         crud = CRUD_DataBase()
         value = crud.dropDatabase(name_database)
         if value == 0:
             messagebox.showinfo('', 'Operacion Exitosa')
             window.destroy()
         elif value == 2:
             messagebox.showinfo('', 'Base de Datos No Existente')
         else:
             messagebox.showinfo('', 'Error en la Operacion')
Ejemplo n.º 5
0
 def modificar():
     nombre_anterior = txtAnterior.get()
     nombre_nuevo= txtNueva.get()
     if nombre_anterior and nombre_nuevo:
         txtAnterior.delete(0, END)
         txtNueva.delete(0, END)
         crud = CRUD_DataBase()
         value = crud.alterDatabase(nombre_anterior, nombre_nuevo)
         if value == 0:
             messagebox.showinfo('', 'Operacion Exitosa')
         elif value == 2:
             messagebox.showinfo('', 'databaseOld No Existente')
         elif value == 3:
             messagebox.showinfo('', 'databaseNew Existente')
         else:
             messagebox.showinfo('', 'Error en la Operacion')
Ejemplo n.º 6
0
    def alterTable(self, database, tableOld, tableNew):

        existe_database = CRUD_DataBase().searchDatabase(database)
        if existe_database:
            existe_tableOld = copy.deepcopy(self.extractTable(database, tableOld))
            if existe_tableOld:
                existe_tableNew = self.extractTable(database, tableNew)
                if existe_tableNew is None:

                    existe_tableOld.name = tableNew
                    val_drop = self.dropTable(database, tableOld)

                    if val_drop == 0:
                        val_assign = self.createTable_Object(database, tableNew, existe_tableOld)
                        return val_assign
                    elif val_drop == 2:
                        return 2
                    else:
                        return 1
                else:
                    return 4
            else:
                return 3
        else:
            return 2
Ejemplo n.º 7
0
 def dropTable(self, database, table):
     try:
         temp = CRUD_DataBase().searchDatabase(database)
         if temp:
             tmp = CRUD_DataBase().getRoot()
             existencia_tabla = self.extractTable(database, table)
             if existencia_tabla:
                 self._dropTable(database, tmp, table)
                 CRUD_DataBase().saveRoot(tmp)
                 return 0
             else:
                 return 3
         else:
             return 2
     except:
         return 1
Ejemplo n.º 8
0
    def createTable_Object(self, database, table, object_table):

        r_basededatos = CRUD_DataBase().searchDatabase(database)
        if r_basededatos:
            r_tabla = self.extractTable(database, table)
            if r_tabla is None:
                tmp = CRUD_DataBase().getRoot()
                r_value = self._createTable(database, tmp, object_table)
                if r_value:
                    CRUD_DataBase().saveRoot(tmp)
                    return 0
                else:
                    return 1
            else:
                return 3
        else:
            return 2
Ejemplo n.º 9
0
    def createTable(self, database, table, numberColumns):

        r_basededatos = CRUD_DataBase().searchDatabase(database)
        if r_basededatos:
            r_tabla = self.extractTable(database, table)
            if r_tabla is None:
                tmp = CRUD_DataBase().getRoot()
                table_temp = Tabla(table, numberColumns)
                r_value = self._createTable(database, tmp, table_temp)
                if r_value:
                    CRUD_DataBase().saveRoot(tmp)
                    return 0
                else:
                    return 1
            else:
                return 3
        else:
            return 2
Ejemplo n.º 10
0
 def extractTable(self, database, table):
     temp = CRUD_DataBase().searchDatabase(database)
     try:
         tablas = temp.tables
         for i in tablas:
             if i.name == table:
                 return i
     except:
         return None
Ejemplo n.º 11
0
 def alterDropPK(self, database, table):
     try:
         search = CRUD_DataBase().searchDatabase(database)
         if search:
             search_table = self.extractTable(database, table)
             if search_table is None:
                 return 3
             else:
                 temp_pk = search_table.PK
                 if temp_pk[0] is None:
                     return 4
                 else:
                     tmp = CRUD_DataBase().getRoot()
                     validation_aproved = self._alterDropPK(database, table, tmp)
                     if validation_aproved:
                         CRUD_DataBase().saveRoot(tmp)
     except:
         return 1
Ejemplo n.º 12
0
 def shownTables(self, database):
     try:
         temp = CRUD_DataBase().searchDatabase(database)
         lista_retorno = []
         for item in temp.tables:
             # print(item.name)
             lista_retorno.append(item.name)
         return lista_retorno
     except:
         return None
Ejemplo n.º 13
0
 def alterAddColumn(self, database, table, columns):
     try:
         search = CRUD_DataBase().searchDatabase(database)
         if search:
             search_table = self.extractTable(database, table)
             if search_table is None:
                 return 3
             else:
                 tmp = CRUD_DataBase().getRoot()
                 validation_apoved = self._alterAddColumn(database, table, columns, tmp)
                 if validation_apoved:
                     CRUD_DataBase().saveRoot(tmp)
                     return 0
                 else:
                     return 1
         else:
             return 2
     except:
         return 1
Ejemplo n.º 14
0
def mostrarTablas(text):
    crud = CRUD_DataBase()
    objeto = crud.searchDatabase(text)
    # print("objeto: {}".format(objeto.name))
    window = Tk()
    # Centrado de la Ventana
    ancho_ventana = 700
    alto_ventana = 450
    x_ventana = window.winfo_screenwidth() // 2 - ancho_ventana // 2
    y_ventana = window.winfo_screenheight() // 2 - alto_ventana // 2
    posicion = str(ancho_ventana) + "x" + str(alto_ventana) + "+" + str(
        x_ventana) + "+" + str(y_ventana)
    window.geometry(posicion)

    # Edicion de la Ventana
    window.resizable(0, 0)
    window.title("Tablas")
    window.geometry('700x450')

    window.mainloop()
Ejemplo n.º 15
0
def view_showDatabase():
    list_words = CRUD_DataBase().showDatabases()
    var = 0
    # Esta es la ventana principal
    ventana_principal = Tk()
    ventana_principal.title('show Databases')
    ventana_principal.geometry("550x500")

    #---------------------------------------------------------------------------------
    #---------------------------------------------------------------------------------
    # Edicion de la Ventana
    ancho_ventana = 550
    alto_ventana = 500
    x_ventana = ventana_principal.winfo_screenwidth() // 2 - ancho_ventana // 2
    y_ventana = ventana_principal.winfo_screenheight() // 2 - alto_ventana // 2
    posicion = str(ancho_ventana) + "x" + str(alto_ventana) + "+" + str(
        x_ventana) + "+" + str(y_ventana)
    ventana_principal.geometry(posicion)

    # Edicion de la Ventana
    ventana_principal.resizable(0, 0)
    dimension = str(ancho_ventana) + 'x' + str(alto_ventana)
    ventana_principal.geometry(dimension)
    ventana_principal.configure(bg="white")
    #---------------------------------------------------------------------------------
    #---------------------------------------------------------------------------------

    # Se crea un marco principal
    marco_principal = Frame(ventana_principal)
    marco_principal.pack(fill=BOTH, expand=1)

    # Se crea un canvas
    var_canvas = Canvas(marco_principal)
    var_canvas.config(bg="red")
    var_canvas.pack(side=LEFT, fill=BOTH, expand=1)

    # Se agrega un scrollbar al canvas
    var_scrollbar = Scrollbar(marco_principal,
                              orient=VERTICAL,
                              command=var_canvas.yview)
    var_scrollbar.pack(side=RIGHT, fill=Y)

    # Se configura el canvas
    var_canvas.configure(yscrollcommand=var_scrollbar.set)
    var_canvas.bind(
        '<Configure>',
        lambda e: var_canvas.configure(scrollregion=var_canvas.bbox("all")))

    # Se crea otro marco dentro del canvas
    second_frame = Frame(var_canvas)

    # Se agrega ese nuevo marco a la ventana en el canvas
    var_canvas.create_window((0, 0), window=second_frame, anchor="nw")
    var_font = tkFont.Font(size=13, weight="bold", family="Arial")

    for word in list_words:
        btn = Button(
            second_frame,
            text=word,
            width=58,
            height=2,
            bg="#DBE2FC",
            font=var_font,
            command=lambda txt=word: mostrarTablas(txt, ventana_principal))
        btn.grid(row=var, column=0, pady=1)
        var += 1

    ventana_principal.mainloop()
Ejemplo n.º 16
0
def view_showGraphivz():
    CRUD_DataBase().showGraphviz()
Ejemplo n.º 17
0
 def update(self, database, table, register,columns):
     self.root = CRUD_DataBase().getRoot()
     self._update(database, self.root, table, register,columns)
     CRUD_DataBase().saveRoot(self.root)
Ejemplo n.º 18
0
def showDatabases():
    return CRUD_DataBase().showDatabases()
Ejemplo n.º 19
0
def createDatabase(database):
    return CRUD_DataBase().createDatabase(database)
Ejemplo n.º 20
0
def dropDatabase(database):
    return CRUD_DataBase().dropDatabase(database)
Ejemplo n.º 21
0
 def extractRow(self, database, table, tupla):
     self.root = CRUD_DataBase().getRoot()
     self._ext(database, self.root, table, tupla)
     CRUD_DataBase().saveRoot(self.root)
Ejemplo n.º 22
0
 def loadCSV(self, file, database, table):
     self.root = CRUD_DataBase().getRoot()
     self._load(database, self.root, table, file)
     CRUD_DataBase().saveRoot(self.root)
Ejemplo n.º 23
0
 def truncate(self, database, table):
     self.root = CRUD_DataBase().getRoot()
     self._ext(database, self.root, table)
     CRUD_DataBase().saveRoot(self.root)
Ejemplo n.º 24
0
 def insert(self,database,table,tupla):
     self.root = CRUD_DataBase().getRoot()
     self._insert(database, self.root, table,tupla)
     CRUD_DataBase().saveRoot(self.root)
Ejemplo n.º 25
0
def alterDatabase(databaseOld, databaseNew):
    return CRUD_DataBase().alterDatabase(databaseOld, databaseNew)
Ejemplo n.º 26
0
 def delete(self, database, table, tupla):
     self.root = CRUD_DataBase().getRoot()
     self._delete(database, self.root, table, tupla)
     CRUD_DataBase().saveRoot(self.root)