use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testLiteralVariable.
@Test
public void testLiteralVariable() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
evaluator.add("salary", new Value(BigDecimal.class, new BigDecimal(10000)));
String testSql = "select * from aaa where ename = /*^name*/'aaa' and sal = /*^salary*/-2000";
SqlParser parser = new SqlParser(testSql);
SqlNode sqlNode = parser.parse();
PreparedSql sql = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED).build(sqlNode, Function.identity());
assertEquals("select * from aaa where ename = 'hoge' and sal = 10000", sql.getRawSql());
assertEquals("select * from aaa where ename = 'hoge' and sal = 10000", sql.getFormattedSql());
assertEquals(0, sql.getParameters().size());
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testSelect.
@Test
public void testSelect() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
evaluator.add("count", new Value(Integer.class, 5));
String testSql = "select aaa.deptname, count(*) from aaa join bbb on aaa.id = bbb.id where aaa.name = /*name*/'ccc' group by aaa.deptname having count(*) > /*count*/10 order by aaa.name for update bbb";
SqlParser parser = new SqlParser(testSql);
SqlNode sqlNode = parser.parse();
PreparedSql sql = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED).build(sqlNode, Function.identity());
assertEquals("select aaa.deptname, count(*) from aaa join bbb on aaa.id = bbb.id where aaa.name = ? group by aaa.deptname having count(*) > ? order by aaa.name for update bbb", sql.getRawSql());
assertEquals("select aaa.deptname, count(*) from aaa join bbb on aaa.id = bbb.id where aaa.name = 'hoge' group by aaa.deptname having count(*) > 5 order by aaa.name for update bbb", sql.getFormattedSql());
assertEquals(2, sql.getParameters().size());
assertEquals("hoge", sql.getParameters().get(0).getWrapper().get());
assertEquals(5, sql.getParameters().get(1).getWrapper().get());
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testIf_removeAnd.
@Test
public void testIf_removeAnd() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, null));
String testSql = "select * from aaa where \n/*%if name != null*/bbb = /*name*/'ccc' \n/*%else*/\n --comment\nand ddd is null\n /*%end*/";
SqlParser parser = new SqlParser(testSql);
SqlNode sqlNode = parser.parse();
PreparedSql sql = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED).build(sqlNode, Function.identity());
assertEquals("select * from aaa where \n\n --comment\n ddd is null", sql.getRawSql());
assertEquals("select * from aaa where \n\n --comment\n ddd is null", sql.getFormattedSql());
assertEquals(0, sql.getParameters().size());
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testExpand.
@Test
public void testExpand() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
String testSql = "select /*%expand*/* from aaa";
SqlParser parser = new SqlParser(testSql);
SqlNode sqlNode = parser.parse();
PreparedSql sql = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED, node -> Arrays.asList("bbb", "ccc")).build(sqlNode, Function.identity());
assertEquals("select bbb, ccc from aaa", sql.getRawSql());
assertEquals("select bbb, ccc from aaa", sql.getFormattedSql());
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testBindVariable_nullLiteral.
@Test
public void testBindVariable_nullLiteral() {
String testSql = "select * from aaa where ename = /*name*/null";
SqlParser parser = new SqlParser(testSql);
SqlNode node = parser.parse();
assertNotNull(node);
}
Aggregations