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());
}
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());
}
Aggregations