use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class SqlParserTest method testIf_removeGroupBy.
@Test
public void testIf_removeGroupBy() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, null));
String testSql = "select * from aaa group by /*%if name != null*/bbb/*%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", sql.getRawSql());
assertEquals("select * from aaa", sql.getFormattedSql());
assertEquals(0, sql.getParameters().size());
}
use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class SqlParserTest method testFor_index.
@Test
public void testFor_index() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
ArrayList<String> list = new ArrayList<>();
list.add("aaa");
list.add("bbb");
list.add("ccc");
evaluator.add("names", new Value(List.class, list));
String testSql = "select * from aaa where /*%for n : names*/name/*# n_index */ = /*n*/'a' /*%if n_has_next */or /*%end*//*%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 name0 = ? or name1 = ? or name2 = ?", sql.getRawSql());
assertEquals("select * from aaa where name0 = 'aaa' or name1 = 'bbb' or name2 = 'ccc'", sql.getFormattedSql());
assertEquals(3, sql.getParameters().size());
assertEquals("aaa", sql.getParameters().get(0).getWrapper().get());
assertEquals("bbb", sql.getParameters().get(1).getWrapper().get());
assertEquals("ccc", sql.getParameters().get(2).getWrapper().get());
}
use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class SqlParserTest method testIf_nestContinuously.
@Test
public void testIf_nestContinuously() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
evaluator.add("name2", new Value(String.class, null));
String testSql = "select * from aaa where /*%if name != null*//*%if name2 == \"hoge\"*/ ddd = eee/*%end*//*%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", sql.getRawSql());
assertEquals("select * from aaa", sql.getFormattedSql());
assertEquals(0, sql.getParameters().size());
}
use of org.seasar.doma.internal.expr.Value 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.internal.expr.Value 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());
}
Aggregations