def execute(self, environment): Struct.load() result = jsonMode.createDatabase(self.name) """ 0: insert 1: error 2: exists """ if self.mode == None: self.mode = 1 if result == 0: Struct.createDatabase(self.name, self.mode, self.owner) report = "Base de datos: " + self.name + " insertada." elif result == 1: instruction.syntaxPostgreSQL.append("Error: XX000: Error interno") report = "Error al insertar la base de datos: " + self.name elif result == 2 and self.replace: Struct.replaceDatabase(self.name, self.mode, self.owner) report = "Base de datos '" + self.name + " ' reemplazada." elif result == 2 and self.exists: report = "Base de datos no insertada, " + self.name + " ya existe." else: instruction.semanticErrors.append([ "La base de datos " + str(self.name) + " ya existe", self.row ]) instruction.syntaxPostgreSQL.append( "Error: 42P04: La base de datos " + str(self.name) + " ya existe") report = "Error: La base de datos ya existe" return report
def f_elimnar_db(self): dll_db = simpledialog.askstring("Delete DB", "Ingresar nombre") query = "drop database " + dll_db + ";" #print(query) self.send_scritp(query) databases.load() self.f_charge_treeview()
def execute(self, environment): try: Struct.load() # Verificamos que no pueden venir mas de 1 tabla en el clausula FROM if len(self.fromcl.tables) > 1: instruction.semanticErrors.append( ["Error sintactico cerco e en ','", self.row]) instruction.syntaxPostgreSQL.append( "Error: 42601: Error sintactico cerca de , en la linea " + str(self.row)) return "Error: syntax error at or near ','" newEnv = Environment(environment, instruction.dbtemp) instruction.envVariables.append(newEnv) self.fromcl.execute(newEnv) value = [newEnv.dataFrame[p] for p in newEnv.dataFrame] labels = [p for p in newEnv.dataFrame] for i in range(len(labels)): newEnv.dataFrame[labels[i]] = value[i] if self.wherecl == None: w2 = newEnv.dataFrame.filter(labels) else: wh = self.wherecl.execute(newEnv) w2 = wh.filter(labels) # Si la clausula WHERE devuelve un dataframe vacio if w2.empty: return "Operacion UPDATE completada" # Logica para realizar el update table = self.fromcl.tables[0].name pk = Struct.extractPKIndexColumns(instruction.dbtemp, table) # Se obtienen las parametros de las llaves primarias para proceder a eliminar rows = [] if pk: for row in w2.values: rows.append([row[p] for p in pk]) else: rows.append([i for i in w2.index]) print(rows) # Obtenemos las variables a cambiar su valor ids = [p.id for p in self.values] values = [p.execute(newEnv).value for p in self.values] ids = Struct.getListIndex(instruction.dbtemp, table, ids) if len(ids) != len(values): return "Error: Columnas no encontradas" temp = {} for i in range(len(ids)): temp[ids[i]] = values[i] print(temp, rows) # TODO: La funcion del STORAGE esta bugueada bug = False for row in rows: result = jsonMode.update(instruction.dbtemp, table, temp, rows) if result != 0: bug = True break if bug: return ["Error: Funcion UPDATE del Storage", temp, rows] return "Operacion UPDATE completada" except: instruction.syntaxPostgreSQL.append( "Error: P0001: Error en la instruccion UPDATE")
def execute(self, environment): Struct.load() # insert = [posiblesErrores,noColumnas] insert = Struct.insertTable( instruction.dbtemp, self.name, self.columns, self.inherits ) error = insert[0] nCol = insert[1] if not error: error = Checker.checkValue(instruction.dbtemp, self.name) """ Result 0: insert 1: error 2: not found database 3: exists table """ if not error: result = jsonMode.createTable(instruction.dbtemp, self.name, nCol) if result == 0: pass elif result == 1: instruction.syntaxPostgreSQL.append("Error: XX000: Error interno") return "Error: No se puede crear la tabla: " + self.name elif result == 2: instruction.semanticErrors.append( "La base de datos " + instruction.dbtemp + " no existe" ) instruction.syntaxPostgreSQL.append( "Error: 3F000: base de datos" + instruction.dbtemp + " no existe" ) return "Error: Base de datos no encontrada: " + instruction.dbtemp elif result == 3 and self.exists: instruction.semanticErrors.append( ["La tabla " + str(self.name) + " ya existe", self.row] ) instruction.syntaxPostgreSQL.append( "Error: 42P07: La tabla " + str(self.name) + " ya existe" ) return "La tabla ya existe en la base de datos" else: instruction.semanticErrors.append( ["La tabla " + str(self.name) + " ya existe", self.row] ) instruction.syntaxPostgreSQL.append("Error: 42P07: tabla duplicada") return "Error: ya existe la tabla " + self.name pk = Struct.extractPKIndexColumns(instruction.dbtemp, self.name) addPK = 0 if pk: addPK = jsonMode.alterAddPK(instruction.dbtemp, self.name, pk) if addPK != 0: instruction.syntaxPostgreSQL.append( "Error: 23505: Error en llaves primarias de la instruccion CREATE TABLE de la tabla " + str(self.name) ) return "Tabla " + self.name + " creada" else: Struct.dropTable(instruction.dbtemp, self.name) return error
def execute(self, environment): Struct.load() try: if self.structure == "TABLE": if instruction.dbtemp != "": valor = jsonMode.dropTable(instruction.dbtemp, self.name) if valor == 2: instruction.semanticErrors.append([ "La base de datos " + str(instruction.dbtemp) + " no existe", self.row, ]) instruction.syntaxPostgreSQL.append( "Error: 42000: La base de datos " + str(instruction.dbtemp) + " no existe") return "La base de datos no existe" if valor == 3: instruction.semanticErrors.append([ "La tabla " + str(self.name) + " no existe", self.row ]) instruction.syntaxPostgreSQL.append( "Error: 42P01: La tabla " + str(self.name) + " no existe") return "La tabla no existe en la base de datos" if valor == 1: instruction.syntaxPostgreSQL.append( "Error: XX000: Error interno") return "Hubo un problema en la ejecucion de la sentencia DROP" if valor == 0: Struct.dropTable(instruction.dbtemp, self.name) return "DROP TABLE Se elimino la tabla: " + self.name instruction.syntaxPostgreSQL.append( "Error: 42000: Base de datos no especificada ") return "El nombre de la base de datos no esta especificado operacion no realizada" else: valor = jsonMode.dropDatabase(self.name) if valor == 1: instruction.syntaxPostgreSQL.append( "Error: XX000: Error interno") return "Hubo un problema en la ejecucion de la sentencia" if valor == 2: instruction.semanticErrors.append([ "La base de datos " + str(self.name) + " no existe", self.row, ]) instruction.syntaxPostgreSQL.append( "Error: 42000: La base de datos " + str(self.name) + " no existe") return "La base de datos no existe" if valor == 0: Struct.dropDatabase(self.name) return "Instruccion ejecutada con exito DROP DATABASE" instruction.syntaxPostgreSQL.append( "Error: XX000: Error interno DROPTABLE") return "Fatal Error: DROP TABLE" except: instruction.syntaxPostgreSQL.append( "Error: P0001: Error en la instruccion DROP")
def execute(self, environment): Struct.load() alter = Struct.alterColumnsTable(instruction.dbtemp, self.table, self.params) if alter == None: alter = Checker.checkValue(instruction.dbtemp, self.table) Struct.save() if alter == None: alter = "Tabla alterada: " + self.table return alter
def execute(self, environment): Struct.load() lista = [] for value in self.values: lista.append(value.execute(environment).value) result = Struct.createType(self.exists, self.name, lista) if result == None: report = "Type creado" else: report = result return report
def execute(self, environment): Struct.load() try: if self.option == "RENAME": valor = jsonMode.alterDatabase(self.name, self.newname) if valor == 2: instruction.semanticErrors.append([ "La base de datos " + str(self.name) + " no existe", self.row ]) instruction.syntaxPostgreSQL.append( "Error: 42000: La base de datos " + str(self.name) + " no existe") return "La base de datos no existe: '" + self.name + "'." if valor == 3: instruction.semanticErrors.append([ "La base de datos " + str(self.newname) + " ya existe", self.row, ]) instruction.syntaxPostgreSQL.append( "Error: 42P04: La base de datos " + str(self.newname) + " ya existe") return "El nuevo nombre para la base de datos existe" if valor == 1: instruction.syntaxPostgreSQL.append( "Error: XX000: Error interno") return "Hubo un problema en la ejecucion de la sentencia" if valor == 0: Struct.alterDatabaseRename(self.name, self.newname) return ("Base de datos renombrada: " + self.name + " - " + self.newname) return "Error ALTER DATABASE RENAME: " + self.newname elif self.option == "OWNER": valor = Struct.alterDatabaseOwner(self.name, self.newname) if valor == 0: return "Instruccion ejecutada con exito ALTER DATABASE OWNER" instruction.syntaxPostgreSQL.append( "Error: XX000: Error interno") return "Error ALTER DATABASE OWNER" instruction.syntaxPostgreSQL.append("Error: XX000: Error interno") return "Fatal Error ALTER DATABASE: " + self.newname except: instruction.syntaxPostgreSQL.append( "Error: P0001: Error en la instruccion ALTER DATABASE")
def checkInsert(dbName, tableName, columns, values): lstErr.clear() S.load() if columns != None: if len(columns) != len(values): return "Columnas fuera de los limites 1" table = S.extractTable(dbName, tableName) values = S.getValues(table, columns, values) if table == 0: return "No existe la base de datos" elif table == 1: return "No existe la tabla" elif len(table["columns"]) != len(values): return "Columnas fuera de los limites 2" else: pass indexCol = 0 for value in values: column = table["columns"][indexCol] if value != None and value.type != TYPE.NULL: if column["Unique"] or column["PK"]: validateUnique(dbName, tableName, value.value, indexCol) if column["FK"] != None: validateForeign(dbName, column["FK"], value.value) if column["Constraint"] != None: validateConstraint( column["Constraint"], values, dbName, tableName, column["type"] ) select(column, value) else: validateNotNull(column["NN"], column["name"]) indexCol += 1 return [listError(), values]
def execute(self, environment): Struct.load() tempDf = None for i in range(len(self.tables)): exec = self.tables[i].execute(environment) data = exec[0] types = exec[1] if isinstance(self.tables[i], Select): newNames = {} subqAlias = self.aliases[i] for (columnName, columnData) in data.iteritems(): colSplit = columnName.split(".") if len(colSplit) >= 2: newNames[columnName] = subqAlias + "." + colSplit[1] types[subqAlias + "." + colSplit[1]] = columnName else: newNames[columnName] = subqAlias + "." + colSplit[0] types[subqAlias + "." + colSplit[0]] = columnName data.rename(columns=newNames, inplace=True) environment.addVar(subqAlias, subqAlias, "TABLE", self.row, self.column) else: sym = Symbol( self.tables[i].name, None, self.tables[i].row, self.tables[i].column, ) environment.addSymbol(self.tables[i].name, sym) if self.aliases[i]: environment.addSymbol(self.aliases[i], sym) if i == 0: tempDf = data else: tempDf = self.crossJoin([tempDf, data]) environment.dataFrame = tempDf try: environment.types.update(types) except: instruction.syntaxPostgreSQL.append( "Error: P0001: Error en la instruccion SELECT clausula FROM" ) return
def execute(self, environment): Struct.load() name = self.idIndex if self.existIndex(name): return "Error: ya existe un index con el nombre " + name table = Struct.extractTable(instruction.dbtemp, self.idTable) if table == 1 or table == 0: return ("Error: no existe la tabla " + self.idTable + " en la base de datos " + instruction.dbtemp) try: Index = File.importFile("Index") indexBody = {} indexBody["Table"] = self.idTable indexBody["Unique"] = self.unique indexBody["Method"] = self.usingMethod indexBody["Columns"] = [] for c in self.optList: col = {} col["Name"] = c[0] col["Order"] = c[1] if c[2]: nulls = c[2][0] if c[2][1]: nulls += " " + c[2][1] else: if col["Order"] == "DESC": nulls = "NULLS FIRST" else: nulls = "NULLS LAST" col["Nulls"] = nulls indexBody["Columns"].append(col) Index[name] = indexBody File.exportFile(Index, "Index") return "Index " + name + " creado" except: return "Error fatal"
def f_conectar(self): print("Conectando...") self.send_scritp('tytus.connect_server') databases.load() self.f_charge_treeview()
def __init__(self, img_carpeta, iconos): self.consoleMode = False databases.load() self.databases = databases.Databases databases.load() # Creacion de la Ventana self.raiz = Tk() self.f_log() self.treeview = ttk.Treeview(self.raiz) # Definicion de Iconos self.img_carpeta = img_carpeta self.iconos = iconos self.PYREMOTO_ICON = PhotoImage(file=self.iconos[0]) self.START_ICON = PhotoImage(file=self.iconos[3]) self.CONNECT_ICON = PhotoImage(file=self.iconos[4]) self.EXIT_ICON = PhotoImage(file=self.iconos[5]) self.GRUPO_ICON = PhotoImage(file=self.iconos[6]) self.TYTUS_ICON = PhotoImage(file=self.iconos[7]) self.OPEN_ICON = PhotoImage(file=self.iconos[8]) self.SAVE_ICON = PhotoImage(file=self.iconos[9]) self.SERV_ICON = PhotoImage(file=self.iconos[10]) self.BD_ICON = PhotoImage(file=self.iconos[11]) self.TB_ICON = PhotoImage(file=self.iconos[12]) self.COL_ICON = PhotoImage(file=self.iconos[13]) self.CONSOLE_ICON = PhotoImage(file=self.iconos[14]) self.TBASE_ICON = PhotoImage(file=self.iconos[15]) self.TCARPETA_ICON = PhotoImage(file=self.iconos[16]) self.TGUARDAR_ICON = PhotoImage(file=self.iconos[17]) self.TBUSCAR_ICON = PhotoImage(file=self.iconos[18]) self.TVACIAR_ICON = PhotoImage(file=self.iconos[19]) self.TCOMPILAR_ICON = PhotoImage(file=self.iconos[20]) self.TEXPLICAR_ICON = PhotoImage(file=self.iconos[21]) self.TDESCARGAR_ICON = PhotoImage(file=self.iconos[22]) self.TCERRAR_ICON = PhotoImage(file=self.iconos[23]) # Preconfiguracion de la ventana self.raiz.title("TytusDB ") self.raiz.iconphoto(self.raiz, self.PYREMOTO_ICON) self.raiz.option_add("*Font", "Helvetica 12") self.raiz.option_add('*tearOff', True) self.raiz.attributes('-fullscreen', True) self.raiz.minsize(400, 300) self.fuente = font.Font(weight='normal') self.CFG_TIPOCONEX = IntVar() self.CFG_TIPOCONEX.set(1) self.CFG_TIPOEMUT = IntVar() self.CFG_TIPOEMUT.set(1) self.CFG_TIPOEXP = IntVar() self.CFG_TIPOEXP.set(1) self.estado = IntVar() self.estado.set(1) # Definicion del Menu barramenu = Menu(self.raiz) self.raiz['menu'] = barramenu self.fileMenu = Menu(barramenu) self.objectMenu = Menu(barramenu) self.toolsMenu = Menu(barramenu) self.aboutMenu = Menu(barramenu) barramenu.add_cascade(menu=self.fileMenu, label='FILE') barramenu.add_cascade(menu=self.objectMenu, label='OBJECT') barramenu.add_cascade(menu=self.toolsMenu, label='TOOLS') barramenu.add_cascade(menu=self.aboutMenu, label='ABOUT') # Programacion del Menu de Archivos self.fileMenu.add_command(label=' Abrir archivo *.sql', underline=0, command=self.f_cargar, image=self.OPEN_ICON, compound=LEFT) self.fileMenu.add_command(label=' Guardar archivo *.sql', underline=0, command=self.f_guardar, image=self.SAVE_ICON, compound=LEFT) # Programacion del Menu de Objetos # Programacion del Menu de Herramientas self.toolsMenu.add_command(label="Query Tool", command=self.f_query_tool, image=self.START_ICON, compound=LEFT) self.toolsMenu.add_command(label="Crear DB", command=self.f_crear_db, image=self.START_ICON, compound=LEFT) self.toolsMenu.add_command(label="Eliminar DB", command=self.f_elimnar_db, image=self.START_ICON, compound=LEFT) # Programacion del Menu de informacion self.aboutMenu.add_command(label="GRUPO 10", command=self.f_integrantes, image=self.GRUPO_ICON, compound=LEFT) self.aboutMenu.add_command(label="TytusDB", command=self.f_web, image=self.TYTUS_ICON, compound=LEFT) # Definicion de la Barra De Herramientas barraherr = Frame(self.raiz, relief=RAISED, bd=2, bg="#E5E5E5") barraherr.pack(side=TOP, fill=X) # Programacion del Boton de salida de la aplicacion bot2 = Button(barraherr, image=self.EXIT_ICON, command=self.f_salir) bot2.pack(side=RIGHT, padx=1, pady=1) # Programacion del Boton de conexion a la base de datos bot1 = Button(barraherr, image=self.CONNECT_ICON, command=self.f_conectar) bot1.pack(side=RIGHT, padx=2, pady=2) # Barra Inferior now = datetime.now() format = now.strftime( 'Día :%d, Mes: %m, Año: %Y, Hora: %H, Minutos: %M, Segundos: %S') print(format) mensaje = " " + format self.barraest = Label(self.raiz, text=mensaje, bd=1, relief=SUNKEN, anchor=W) self.barraest.pack(side=BOTTOM, fill=X) self.menucontext = Menu(self.raiz, tearoff=FALSE) self.menucontext.add_command(label="Salir", command=self.f_salir, compound=LEFT) # Definicion del Cuerpo de la Aplicacion # Cuerpo Principal cuerpo = Frame(self.raiz, relief=RAISED, bd=2, bg='white') cuerpo.pack(side=BOTTOM, fill=BOTH, expand=True) # Cuerpo del Treeview treeFrame = LabelFrame(cuerpo, bg="white") treeFrame.config(bg='steelblue', width="300") treeFrame.pack(side=LEFT, fill=Y) style = ttk.Style(treeFrame) style.configure('Treeview', rowheight=40) self.treeview = ttk.Treeview(treeFrame, selectmode="extended") self.treeview.column("#0", anchor=W, width=300) self.f_charge_treeview() self.treeview.pack(fill=BOTH, expand=True) # SubCuerpo SubCuerpo = Frame(cuerpo) SubCuerpo.config(bg='white') SubCuerpo.pack(side=LEFT, fill=BOTH, expand=True) # QueryTool self.QueryTool = Frame(SubCuerpo) self.QueryTool.config(bg='white', height="400") self.QueryTool.pack(side=TOP, fill=X) # QueryTool Edit Text self.QueryTool2 = Frame(SubCuerpo) self.QueryTool2.config(bg='green', height="400") self.QueryTool2.pack(side=TOP, fill=X) self.QueryTool2.pack_forget() #botones toolbar3 = Label(self.QueryTool2, bg="Gainsboro") toolbar3.pack(side=TOP, fill=X) btnBase = Button(toolbar3, image=self.TBASE_ICON, command=self.f_cargar) # btnBase.grid(row=0,column=1, padx=8) btnBase.pack(side=LEFT, padx=2, pady=2) btnCarpeta = Button(toolbar3, image=self.TCARPETA_ICON) # btnCarpeta.grid(row=0,column=2, padx=8) btnCarpeta.pack(side=LEFT, padx=2, pady=2) btnGuardar = Button(toolbar3, image=self.TGUARDAR_ICON, command=self.f_guardar) # btnGuardar.grid(row=0,column=3, padx=8) btnGuardar.pack(side=LEFT, padx=2, pady=2) btnBuscar = Button(toolbar3, image=self.TBUSCAR_ICON, command=self.f_buscar) # btnBuscar.grid(row=0,column=4, padx=8) btnBuscar.pack(side=LEFT, padx=2, pady=2) btnVaciar = Button(toolbar3, image=self.TVACIAR_ICON) # btnVaciar.grid(row=0,column=5, padx=8) btnVaciar.pack(side=LEFT, padx=2, pady=2) btnCompilar = Button(toolbar3, image=self.TCOMPILAR_ICON, command=self.f_compilar) # btnCompilar.grid(row=0,column=6, padx=8) btnCompilar.pack(side=LEFT, padx=2, pady=2) btnExplicar = Button(toolbar3, image=self.TEXPLICAR_ICON) # btnExplicar.grid(row=0,column=7, padx=8) btnExplicar.pack(side=LEFT, padx=2, pady=2) btnDescargar = Button(toolbar3, image=self.TDESCARGAR_ICON) # btnDescargar.grid(row=0,column=8, padx=8) btnDescargar.pack(side=LEFT, padx=2, pady=2) btnCerrar = Button(toolbar3, image=self.TCERRAR_ICON, command=self.f_cerrar_query_tool) # btnCerrar.grid(row=0,column=9, padx=20) btnCerrar.pack(side=LEFT, padx=2, pady=2) #subtitulo toolbar2 = Label(self.QueryTool2, bg="LightSteelBlue") toolbar2.pack(side=TOP, fill=X) tituloQuery = StringVar() tituloQuery.set("Query Editor") barrita = Label(toolbar2, textvar=tituloQuery, justify='left', bg="LightSteelBlue", font=('arial', 11)) barrita.pack(side="left") lista_numeros = Label(self.QueryTool2, bg='Silver', width="3") lista_numeros.pack(side=LEFT, fill=Y) #text scroll = Scrollbar(self.QueryTool2) scroll.pack(side=RIGHT, fill=Y) self.texto = Text(self.QueryTool2) self.texto.pack(fill=BOTH, expand=True) self.texto.config(bd=0, padx=6, pady=4, bg="Beige", font=("Consolas", 12), yscrollcommand=scroll.set) scroll.config(command=self.texto.yview) # Consola self.ConsoleTool = LabelFrame(SubCuerpo, text='Consola') self.ConsoleTool.config(bg='white') self.ConsoleTool.pack(side=BOTTOM, fill=BOTH, expand=True) # Creacion de OUTPUTS TABS self.outputControl = ttk.Notebook(self.ConsoleTool) self.outputTables = ttk.Frame(self.outputControl, height=200) self.outputConsole = ttk.Frame(self.outputControl, height=200) self.outputControl.add(self.outputTables, text='Salida') self.outputControl.add(self.outputConsole, text='Consola') self.outputControl.pack(fill=BOTH, expand=True) # Agregar TextBox al outputConsola self.outputText = Text(self.outputConsole, pady=2, padx=2, state='disabled') self.outputText.pack(fill=BOTH, expand=True) self.f_set_console_message('Cliente Iniciado.\n') # Agregar Tablas al outputTables self.outputQuery = ttk.Treeview(self.outputTables) self.outputQuery.pack(fill=BOTH, expand=True) # Ejecucion de la ventana self.raiz.mainloop()
def execute(self, environment): try: Struct.load() lista = [] params = [] tab = self.tabla for p in self.parametros: params.append(p.execute(environment)) result = Checker.checkInsert(instruction.dbtemp, self.tabla, self.columns, params) if result[0] == None: for p in result[1]: if p == None: lista.append(p) else: lista.append(p.value) res = jsonMode.insert(instruction.dbtemp, tab, lista) if res == 2: instruction.semanticErrors.append([ "La base de datos " + instruction.dbtemp + " no existe", self.row, ]) instruction.syntaxPostgreSQL.append( "Error: 42000: La base de datos " + str(instruction.dbtemp) + " no existe") return "La base de datos no existe" elif res == 3: instruction.semanticErrors.append( ["La tabla " + str(tab) + " no existe", self.row]) instruction.syntaxPostgreSQL.append( "Error: 42P01: La tabla " + str(tab) + " no existe") return "No existe la tabla" elif res == 5: instruction.semanticErrors.append([ "La instruccion INSERT tiene mas o menos registros que columnas", self.row, ]) instruction.syntaxPostgreSQL.append( "Error: 42611: INSERT tiene mas o menos registros que columnas " ) return "Columnas fuera de los limites" elif res == 4: instruction.semanticErrors.append([ "El valor de la clave esta duplicada, viola la restriccion unica", self.row, ]) instruction.syntaxPostgreSQL.append( "Error: 23505: el valor de clave esta duplicada, viola la restricción única " ) return "Llaves primarias duplicadas" elif res == 1: instruction.syntaxPostgreSQL.append( "Error: XX000: Error interno") return "Error en la operacion" elif res == 0: return "Fila Insertada correctamente" else: return result[0] except: instruction.syntaxPostgreSQL.append( "Error: P0001: Error en la instruccion INSERT") pass
from enum import Enum from analizer.abstract import expression import analizer.typechecker.Metadata.Struct as S from analizer.abstract.expression import Expression from analizer.typechecker.Types.Type import Type from analizer.typechecker.Types.Type import TypeNumber from analizer.typechecker.Types.Validations import Number as N from analizer.typechecker.Types.Validations import Character as C from analizer.typechecker.Types.Validations import Time as T from storage.storageManager import jsonMode from analizer.abstract.expression import TYPE from datetime import datetime lstErr = [] dbActual = "" S.load() syntaxPostgreErrors = [] def addError(error): if error != None: lstErr.append(error) def unir(errors): for err in errors: lstErr.append(err) def numeric(col, val):
from analizer.abstract import instruction as inst from analizer.typechecker.Metadata import Struct from analizer.reports import Nodo from storage.storageManager import jsonMode # carga de datos Struct.load() # listas encargadas de almacenar los errores semanticos syntaxPostgreSQL = list() semanticErrors = list() class AlterDataBase(inst.Instruction): def __init__(self, option, name, newname): self.option = option # define si se renombra o se cambia de dueño self.name = name # define el nombre nuevo de la base de datos o el nuevo dueño self.newname = newname def execute(self, environment): try: if self.option == "RENAME": valor = jsonMode.alterDatabase(self.name, self.newname) if valor == 2: semanticErrors.append([ "La base de datos " + str(self.name) + " no existe", self.row ]) syntaxPostgreSQL.append( "Error: 42000: La base de datos " + str(self.name) + " no existe")
def __init__(self, img_carpeta, iconos): self.consoleMode = False self.send_scritp('create database shooooooooooooooooo___x2_alv;') databases.load() print(databases.Databases) # Creacion de la Ventana self.raiz = Tk() self.f_log() self.treeview = ttk.Treeview(self.raiz) ''' iconos = (ruta_r + "pyremoto64x64.png", ruta_r + "conec16x16.png", ruta_r + "salir16x16.png", ruta_r + "star16x16.png", ruta_r + "conec32x32.png", ruta_r + "salir32x32.png", ruta_r + "grupo32x32.png", ruta_r + "tytusdb.png", ruta_r + "open.png", ruta_r + "save.png", ruta_r + "serv.png") ''' # Definicion de Iconos self.img_carpeta = img_carpeta self.iconos = iconos self.PYREMOTO_ICON = PhotoImage(file=self.iconos[0]) # icono2 = PhotoImage(file=self.iconos[1]) # icono3 = PhotoImage(file=self.iconos[2]) self.START_ICON = PhotoImage(file=self.iconos[3]) self.CONNECT_ICON = PhotoImage(file=self.iconos[4]) self.EXIT_ICON = PhotoImage(file=self.iconos[5]) self.GRUPO_ICON = PhotoImage(file=self.iconos[6]) self.TYTUS_ICON = PhotoImage(file=self.iconos[7]) self.OPEN_ICON = PhotoImage(file=self.iconos[8]) self.SAVE_ICON = PhotoImage(file=self.iconos[9]) self.SERV_ICON = PhotoImage(file=self.iconos[10]) self.BD_ICON = PhotoImage(file = self.iconos[11]) self.TB_ICON = PhotoImage(file = self.iconos[12]) self.COL_ICON = PhotoImage(file = self.iconos[13]) self.CONSOLE_ICON = PhotoImage(file = self.iconos[14]) self.TBASE_ICON = PhotoImage(file=self.iconos[15]) self.TCARPETA_ICON = PhotoImage(file=self.iconos[16]) self.TGUARDAR_ICON = PhotoImage(file=self.iconos[17]) self.TBUSCAR_ICON = PhotoImage(file=self.iconos[18]) self.TVACIAR_ICON = PhotoImage(file=self.iconos[19]) self.TCOMPILAR_ICON = PhotoImage(file=self.iconos[20]) self.TEXPLICAR_ICON = PhotoImage(file=self.iconos[21]) self.TDESCARGAR_ICON = PhotoImage(file=self.iconos[22]) self.TCERRAR_ICON = PhotoImage(file=self.iconos[23]) # Preconfiguracion de la ventana self.raiz.title("TytusDB ") self.raiz.iconphoto(self.raiz, self.PYREMOTO_ICON) self.raiz.option_add("*Font", "Helvetica 12") self.raiz.option_add('*tearOff', True) self.raiz.attributes('-fullscreen', True) self.raiz.minsize(400, 300) self.fuente = font.Font(weight='normal') self.CFG_TIPOCONEX = IntVar() self.CFG_TIPOCONEX.set(1) self.CFG_TIPOEMUT = IntVar() self.CFG_TIPOEMUT.set(1) self.CFG_TIPOEXP = IntVar() self.CFG_TIPOEXP.set(1) self.estado = IntVar() self.estado.set(1) # Definicion del Menu barramenu = Menu(self.raiz) self.raiz['menu'] = barramenu self.fileMenu = Menu(barramenu) self.objectMenu = Menu(barramenu) self.toolsMenu = Menu(barramenu) self.aboutMenu = Menu(barramenu) barramenu.add_cascade(menu=self.fileMenu, label='FILE') barramenu.add_cascade(menu=self.objectMenu, label='OBJECT') barramenu.add_cascade(menu=self.toolsMenu, label='TOOLS') barramenu.add_cascade(menu=self.aboutMenu, label='ABOUT') # Programacion del Menu de Archivos self.fileMenu.add_command(label=' Abrir archivo *.sql', underline=0,command=self.f_cargar, image=self.OPEN_ICON, compound=LEFT) self.fileMenu.add_command(label=' Guardar archivo *.sql', underline=0,command = self.f_guardar, image=self.SAVE_ICON, compound=LEFT) # Programacion del Menu de Objetos # Programacion del Menu de Herramientas self.toolsMenu.add_command( label="Query Tool", command=self.f_query_tool, image=self.START_ICON, compound=LEFT) self.toolsMenu.add_command( label="Crear DB", command=self.f_crear_db, image=self.START_ICON, compound=LEFT) # Programacion del Menu de informacion self.aboutMenu.add_command( label="GRUPO 10", command=self.f_integrantes, image=self.GRUPO_ICON, compound=LEFT) self.aboutMenu.add_command( label="TytusDB", command=self.f_web, image=self.TYTUS_ICON, compound=LEFT) # Definicion de la Barra De Herramientas barraherr = Frame(self.raiz, relief=RAISED, bd=2, bg="#E5E5E5") barraherr.pack(side=TOP, fill=X) # Programacion del Boton de salida de la aplicacion bot2 = Button(barraherr, image=self.EXIT_ICON, command=self.f_salir) bot2.pack(side=RIGHT, padx=1, pady=1) # Programacion del Boton de conexion a la base de datos bot1 = Button(barraherr, image=self.CONNECT_ICON, command=self.f_conectar) bot1.pack(side=RIGHT, padx=2, pady=2) # Programacion de consola de PRUEBA, es unicamente para probar el switch de la consola botconsole = Button(barraherr, image = self.CONSOLE_ICON, command = self.f_switch_console_mode) botconsole.pack(side=RIGHT, padx=2, pady=2) # Barra Inferior now = datetime.now() format = now.strftime( 'Día :%d, Mes: %m, Año: %Y, Hora: %H, Minutos: %M, Segundos: %S') print(format) mensaje = " " + format self.barraest = Label(self.raiz, text=mensaje, bd=1, relief=SUNKEN, anchor=W) self.barraest.pack(side=BOTTOM, fill=X) self.menucontext = Menu(self.raiz, tearoff=FALSE) self.menucontext.add_command( label="Salir", command=self.f_salir, compound=LEFT) # Definicion del Cuerpo de la Aplicacion # Cuerpo Principal cuerpo = Frame(self.raiz, relief=RAISED, bd=2, bg = 'white') cuerpo.pack(side=BOTTOM, fill=BOTH, expand=True) # Cuerpo del Treeview treeFrame = LabelFrame(cuerpo,bg="white") treeFrame.config(bg='steelblue', width="300") treeFrame.pack(side=LEFT, fill=Y) style = ttk.Style(treeFrame) style.configure('Treeview', rowheight=40) self.treeview = ttk.Treeview(treeFrame, selectmode="extended") self.treeview.column("#0", anchor=W, width=300) item = self.treeview.insert("", tk.END, text=" Server", image=self.SERV_ICON) for x in self.databases: item2 = self.treeview.insert(item, tk.END,text=" "+x['name'],image=self.BD_ICON) item3 = self.treeview.insert(item2, tk.END, text=" Tables",image=self.TB_ICON) for y in x['tables']: item4 = self.treeview.insert(item3, tk.END, text=" "+y['name'],image=self.TB_ICON) for z in y['columns']: self.treeview.insert(item4, tk.END, text=" "+z['name'],image=self.COL_ICON) self.treeview.pack(fill=BOTH, expand=True) # SubCuerpo SubCuerpo = Frame(cuerpo) SubCuerpo.config(bg='white') SubCuerpo.pack(side=LEFT, fill=BOTH, expand=True) # QueryTool self.QueryTool = Frame(SubCuerpo) self.QueryTool.config(bg = 'white', height = "400") self.QueryTool.pack(side = TOP, fill = X) # QueryTool Edit Text self.QueryTool2 = Frame(SubCuerpo) self.QueryTool2.config(bg = 'green', height = "400") self.QueryTool2.pack(side = TOP, fill = X) self.QueryTool2.pack_forget() #botones toolbar3 = Label(self.QueryTool2, bg="Gainsboro") toolbar3.pack(side=TOP, fill = X) btnBase = Button(toolbar3, image=self.TBASE_ICON,command=self.f_cargar) # btnBase.grid(row=0,column=1, padx=8) btnBase.pack(side = LEFT, padx=2, pady=2) btnCarpeta = Button(toolbar3, image=self.TCARPETA_ICON) # btnCarpeta.grid(row=0,column=2, padx=8) btnCarpeta.pack(side = LEFT, padx=2, pady=2) btnGuardar = Button(toolbar3, image=self.TGUARDAR_ICON,command = self.f_guardar) # btnGuardar.grid(row=0,column=3, padx=8) btnGuardar.pack(side = LEFT, padx=2, pady=2) btnBuscar = Button(toolbar3, image=self.TBUSCAR_ICON,command = self.f_buscar) # btnBuscar.grid(row=0,column=4, padx=8) btnBuscar.pack(side = LEFT, padx=2, pady=2) btnVaciar = Button(toolbar3, image=self.TVACIAR_ICON) # btnVaciar.grid(row=0,column=5, padx=8) btnVaciar.pack(side = LEFT, padx=2, pady=2) btnCompilar = Button(toolbar3, image=self.TCOMPILAR_ICON,command = self.f_compilar) # btnCompilar.grid(row=0,column=6, padx=8) btnCompilar.pack(side = LEFT, padx=2, pady=2) btnExplicar = Button(toolbar3, image=self.TEXPLICAR_ICON) # btnExplicar.grid(row=0,column=7, padx=8) btnExplicar.pack(side = LEFT, padx=2, pady=2) btnDescargar = Button(toolbar3, image=self.TDESCARGAR_ICON) # btnDescargar.grid(row=0,column=8, padx=8) btnDescargar.pack(side = LEFT, padx=2, pady=2) btnCerrar = Button(toolbar3, image=self.TCERRAR_ICON, command=self.f_cerrar_query_tool) # btnCerrar.grid(row=0,column=9, padx=20) btnCerrar.pack(side = LEFT, padx=2, pady=2) #subtitulo toolbar2 = Label(self.QueryTool2, bg="LightSteelBlue") toolbar2.pack(side=TOP, fill = X) tituloQuery = StringVar() tituloQuery.set("Query Editor") barrita = Label(toolbar2, textvar=tituloQuery, justify = 'left', bg="LightSteelBlue", font=('arial',11)) barrita.pack(side = "left") lista_numeros = Label(self.QueryTool2, bg = 'Silver', width = "3") lista_numeros.pack(side = LEFT, fill = Y) #text scroll = Scrollbar(self.QueryTool2) scroll.pack(side=RIGHT, fill = Y) texto = Text(self.QueryTool2) texto.pack(fill = BOTH, expand = True) texto.config(bd=0, padx=6, pady=4, bg="Beige", font=("Consolas", 12), yscrollcommand=scroll.set) scroll.config(command=texto.yview) # Consola self.ConsoleTool = LabelFrame(SubCuerpo, text='Consola') self.ConsoleTool.config(bg='white') self.ConsoleTool.pack(side=BOTTOM, fill=BOTH, expand = True) # Primera Configuracion de TextBox self.output = Text(self.ConsoleTool, pady = 1, padx = 1, state = 'normal', height = 12) self.output.pack(side=BOTTOM, fill=BOTH, expand = True) self.output.insert(INSERT, '''Error: Ha ocurrido un error > Este mensaje se mostrara cuando ocurra un error o cuando se deba mostrar el log > de alguna funcion de la base de datos o de la aplicacion ''') self.output.tag_add('error', '1.0', '1.6') self.output.tag_config('error', foreground="red") self.output.config(state = 'disabled') # Ejecucion de la ventana self.raiz.mainloop()