use of org.seasar.doma.internal.expr.Value 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.internal.expr.Value in project doma by domaframework.
the class SqlParserTest method testBindVariable_endsWithBindVariableComment.
@Test
public void testBindVariable_endsWithBindVariableComment() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
String testSql = "select * from aaa where ename = /*name*/";
SqlParser parser = new SqlParser(testSql);
try {
parser.parse();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(Message.DOMA2110, expected.getMessageResource());
}
}
use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class SqlParserTest method testFor_removeOrderBy.
@Test
public void testFor_removeOrderBy() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
ArrayList<String> list = new ArrayList<>();
evaluator.add("names", new Value(List.class, list));
String testSql = "select * from aaa order by /*%for n : names*/name = /*n*/'a' /*%if n_has_next */, /*%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 NodePreparedSqlBuilderTest method testWhere_embeddedVariable_orderBy_followedByForUpdate.
@Test
public void testWhere_embeddedVariable_orderBy_followedByForUpdate() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("embedded", new Value(String.class, "order by bbb"));
String testSql = "select * from aaa where /*%if false*/ename = 'aaa'/*%end */ /*#embedded*/ for update";
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 order by bbb for update", sql.getRawSql());
}
use of org.seasar.doma.internal.expr.Value in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testEmbeddedVariable_lineComment.
@Test
public void testEmbeddedVariable_lineComment() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
evaluator.add("salary", new Value(BigDecimal.class, new BigDecimal(10000)));
evaluator.add("orderBy", new Value(String.class, "aaa--bbb"));
String testSql = "select * from aaa where ename = /*name*/'aaa' and sal = /*salary*/-2000 /*#orderBy*/";
SqlParser parser = new SqlParser(testSql);
SqlNode sqlNode = parser.parse();
try {
new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED).build(sqlNode, Function.identity());
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(Message.DOMA2122, expected.getMessageResource());
}
}
Aggregations