def analize(self, entrada): self.refresh() result = interpreter.execution(entrada) self.lexicalErrors = result["lexical"] self.syntacticErrors = result["syntax"] self.semanticErrors = result["semantic"] self.postgreSQL = result["postgres"] self.ts = result["symbols"] if (len(self.lexicalErrors) + len(self.syntacticErrors) + len(self.semanticErrors) + len(self.postgreSQL) > 0): #print('La consulta contiene errores') if len(self.postgreSQL) > 0: i = 0 self.console += '-----------ERRORS----------\n' while i < len(self.postgreSQL): self.console += self.postgreSQL[i] + "\n" i += 1 messages = result["messages"] if len(messages) > 0: i = 0 self.console += '-----------MESSAGES----------\n' while i < len(messages): if messages[i] != None: self.console += str(messages[i]) + "\n" i += 1 self.console += '--------------QUERYS----------------\n' querys = result["querys"] self.show_result(querys)
def create(name): try: query = f'CREATE DATABASE IF NOT EXISTS {name};' result = interpreter.execution(query) return {"result": result, "ok": True}, 200 except Exception as e: print(e) return {"ok": False}, 400
def analize1(self, entrada) -> str: self.refresh() result = interpreter.execution(entrada) querys = result["querys"] try: resultado = str(querys[0][1]) return resultado except: resultado = 'error' return resultado
def exec(): """Ejecuta una consulta y devuelve el resultado""" # Recupera la consulta a ejecutar body = request.get_json() query = body.get('query') try: # Ejecuta el query (con el interpreter) result = interpreter.execution(query) result = json.loads(json.dumps(result, ignore_nan=True)) return {"result": result, "ok": True}, 200 except Exception as e: # Retorna un mensaje de error en el servidor print(e) return {"ok": False}, 400