Search in sources :

Example 6 with SimpleNode

use of net.sf.jsqlparser.parser.SimpleNode in project JSqlParser by JSQLParser.

the class SelectASTTest method testSelectASTCommentCRLF.

@Test
public void testSelectASTCommentCRLF() throws JSQLParserException {
    String sql = "SELECT  /* testcomment */ \r\n a,  b FROM  -- testcomment2 \r\n mytable \r\n order by   b,  c";
    StringBuilder b = new StringBuilder(sql);
    Statement stmt = CCJSqlParserUtil.parse(sql);
    Select select = (Select) stmt;
    PlainSelect ps = (PlainSelect) select.getSelectBody();
    for (SelectItem item : ps.getSelectItems()) {
        SelectExpressionItem sei = (SelectExpressionItem) item;
        Column c = (Column) sei.getExpression();
        SimpleNode astNode = c.getASTNode();
        assertNotNull(astNode);
        b.setCharAt(astNode.jjtGetFirstToken().absoluteBegin - 1, '*');
    }
    for (OrderByElement item : ps.getOrderByElements()) {
        Column c = (Column) item.getExpression();
        SimpleNode astNode = c.getASTNode();
        assertNotNull(astNode);
        b.setCharAt(astNode.jjtGetFirstToken().absoluteBegin - 1, '#');
    }
    assertEquals("SELECT  /* testcomment */ \r\n *,  * FROM  -- testcomment2 \r\n mytable \r\n order by   #,  #", b.toString());
}
Also used : Column(net.sf.jsqlparser.schema.Column) Statement(net.sf.jsqlparser.statement.Statement) SelectItem(net.sf.jsqlparser.statement.select.SelectItem) SelectExpressionItem(net.sf.jsqlparser.statement.select.SelectExpressionItem) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) Select(net.sf.jsqlparser.statement.select.Select) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) OrderByElement(net.sf.jsqlparser.statement.select.OrderByElement) SimpleNode(net.sf.jsqlparser.parser.SimpleNode) Test(org.junit.Test)

Example 7 with SimpleNode

use of net.sf.jsqlparser.parser.SimpleNode in project JSqlParser by JSQLParser.

the class SelectASTTest method testSelectASTCommentLF.

@Test
public void testSelectASTCommentLF() throws JSQLParserException {
    String sql = "SELECT  /* testcomment */ \n a,  b FROM  -- testcomment2 \n mytable \n order by   b,  c";
    StringBuilder b = new StringBuilder(sql);
    Statement stmt = CCJSqlParserUtil.parse(sql);
    Select select = (Select) stmt;
    PlainSelect ps = (PlainSelect) select.getSelectBody();
    for (SelectItem item : ps.getSelectItems()) {
        SelectExpressionItem sei = (SelectExpressionItem) item;
        Column c = (Column) sei.getExpression();
        SimpleNode astNode = c.getASTNode();
        assertNotNull(astNode);
        b.setCharAt(astNode.jjtGetFirstToken().absoluteBegin - 1, '*');
    }
    for (OrderByElement item : ps.getOrderByElements()) {
        Column c = (Column) item.getExpression();
        SimpleNode astNode = c.getASTNode();
        assertNotNull(astNode);
        b.setCharAt(astNode.jjtGetFirstToken().absoluteBegin - 1, '#');
    }
    assertEquals("SELECT  /* testcomment */ \n *,  * FROM  -- testcomment2 \n mytable \n order by   #,  #", b.toString());
}
Also used : Column(net.sf.jsqlparser.schema.Column) Statement(net.sf.jsqlparser.statement.Statement) SelectItem(net.sf.jsqlparser.statement.select.SelectItem) SelectExpressionItem(net.sf.jsqlparser.statement.select.SelectExpressionItem) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) Select(net.sf.jsqlparser.statement.select.Select) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) OrderByElement(net.sf.jsqlparser.statement.select.OrderByElement) SimpleNode(net.sf.jsqlparser.parser.SimpleNode) Test(org.junit.Test)

Aggregations

SimpleNode (net.sf.jsqlparser.parser.SimpleNode)7 Test (org.junit.Test)7 Column (net.sf.jsqlparser.schema.Column)4 Statement (net.sf.jsqlparser.statement.Statement)4 OrderByElement (net.sf.jsqlparser.statement.select.OrderByElement)4 PlainSelect (net.sf.jsqlparser.statement.select.PlainSelect)4 Select (net.sf.jsqlparser.statement.select.Select)4 SelectExpressionItem (net.sf.jsqlparser.statement.select.SelectExpressionItem)4 SelectItem (net.sf.jsqlparser.statement.select.SelectItem)4 CCJSqlParserDefaultVisitor (net.sf.jsqlparser.parser.CCJSqlParserDefaultVisitor)2