public void testDeparser() throws JSQLParserException {
    String statement =
        "SELECT a.OWNERLASTNAME, a.OWNERFIRSTNAME "
            + "FROM ANTIQUEOWNERS AS a, ANTIQUES AS b "
            + "WHERE b.BUYERID = a.OWNERID AND b.ITEM = 'Chair'";
    Statement parsed = parserManager.parse(new StringReader(statement));
    StatementDeParser deParser = new StatementDeParser(new StringBuffer());
    parsed.accept(deParser);

    assertEquals(statement, deParser.getBuffer().toString());

    statement = "SELECT count(DISTINCT f + 4) FROM a";
    parsed = parserManager.parse(new StringReader(statement));
    deParser = new StatementDeParser(new StringBuffer());
    parsed.accept(deParser);
    assertEquals(statement, parsed.toString());
    assertEquals(statement, deParser.getBuffer().toString());

    statement = "SELECT count(DISTINCT f, g, h) FROM a";
    parsed = parserManager.parse(new StringReader(statement));
    deParser = new StatementDeParser(new StringBuffer());
    parsed.accept(deParser);
    assertEquals(statement, parsed.toString());
    assertEquals(statement, deParser.getBuffer().toString());
  }
  public void testConcat() throws JSQLParserException {
    String statement = "SELECT a || b || c + 4 FROM t";
    Statement parsed = parserManager.parse(new StringReader(statement));
    StatementDeParser deParser = new StatementDeParser(new StringBuffer());
    parsed.accept(deParser);

    assertEquals(statement, parsed.toString());
    assertEquals(statement, deParser.getBuffer().toString());
  }
  public void testMysqlQuote() throws JSQLParserException {
    String statement =
        "SELECT `a.OWNERLASTNAME`, `OWNERFIRSTNAME` "
            + "FROM `ANTIQUEOWNERS` AS a, ANTIQUES AS b "
            + "WHERE b.BUYERID = a.OWNERID AND b.ITEM = 'Chair'";
    Statement parsed = parserManager.parse(new StringReader(statement));
    StatementDeParser deParser = new StatementDeParser(new StringBuffer());
    parsed.accept(deParser);

    assertEquals(statement, parsed.toString());
    assertEquals(statement, deParser.getBuffer().toString());
  }
示例#4
0
 @Override
 public ExecuteSQLOnNodeResponse executeSQLOnNode(ExecuteSQLOnNodeRequest executeSQLOnNodeRequest)
     throws RemoteException {
   Long taskId = executeSQLOnNodeRequest.getTaskId() + delta;
   try {
     Statement stmt = CCJSqlParserUtil.parse(executeSQLOnNodeRequest.getSql());
     SQLStatementVisitor visitor = new SQLStatementVisitor(master, this, taskId);
     stmt.accept(visitor);
     logger.trace("Sending result of query: " + visitor.getResult().getResult());
     return visitor.getResult();
   } catch (JSQLParserException e) {
     logger.error("Sql parsing error: {} - {}", e.getMessage(), e.getStackTrace());
     return new ExecuteSQLOnNodeResponse("", ErrorEnum.SQL_PARSING_ERROR);
   }
 }