use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class SqlParserTest method testFor_array.
@Test
public void testFor_array() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
String[] array = new String[] { "aaa", "bbb", "ccc" };
evaluator.add("names", new Value(String[].class, array));
String testSql = "select * from aaa where /*%for n : names*/name = /*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 name = ? or name = ? or name = ?", sql.getRawSql());
assertEquals("select * from aaa where name = 'aaa' or name = 'bbb' or name = '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 testElseBlock.
@Test
public void testElseBlock() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
String testSql = "select * from aaa where /*%if name == null*/bbb is null\n/*%elseif name == \"\"*/\n/*%else*/ bbb = /*name*/'ccc'/*%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 bbb = ?", sql.getRawSql());
assertEquals("select * from aaa where bbb = 'hoge'", sql.getFormattedSql());
assertEquals(1, sql.getParameters().size());
assertEquals("hoge", sql.getParameters().get(0).getWrapper().get());
}
use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class JdbcExceptionTest method testCollectionOfBindValueContainsNull.
@Test
public void testCollectionOfBindValueContainsNull() {
SqlParser parser = new SqlParser("select * from aaa where bbb in /*bbb*/(1,2,3)");
SqlNode sqlNode = parser.parse();
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("bbb", new Value(List.class, Arrays.asList(1, null)));
NodePreparedSqlBuilder builder = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED);
try {
builder.build(sqlNode, Function.identity());
fail();
} catch (JdbcException e) {
System.out.println(e.getMessage());
assertEquals(Message.DOMA2115, e.getMessageResource());
}
}
use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class StandardPagingTransformerTest method testOffsetLimit_forNode.
@Test
public void testOffsetLimit_forNode() {
String expected = "select * from ( select temp_.*, row_number() over( order by temp_.name1, temp_.name2, temp_.id ) as doma_rownumber_ from ( select emp.id from emp ) as temp_ ) as temp2_ where doma_rownumber_ > 5 and doma_rownumber_ <= 15";
StandardPagingTransformer transformer = new StandardPagingTransformer(5, 10);
SqlParser parser = new SqlParser("select emp.id from emp order by /*%for e: values*/emp.name/*#e*/, /*%end*/emp.id");
SqlNode sqlNode = transformer.transform(parser.parse());
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("values", new Value(List.class, Arrays.asList(1, 2)));
NodePreparedSqlBuilder sqlBuilder = new NodePreparedSqlBuilder(new MockConfig(), SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED);
PreparedSql sql = sqlBuilder.build(sqlNode, Function.identity());
assertEquals(expected, sql.getRawSql());
}
use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class SqlModifyQuery method addParameter.
public void addParameter(String name, Class<?> type, Object value) {
assertNotNull(name, type);
parameters.put(name, new Value(type, value));
}
Aggregations