use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testManyEol.
@Test
public void testManyEol() throws WrapException {
String path = "META-INF/" + getClass().getName().replace('.', '/') + "/manyEol.sql";
String sql = ResourceUtil.getResourceAsString(path);
SqlParser parser = new SqlParser(sql);
SqlNode sqlNode = parser.parse();
assertNotNull(sqlNode);
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testWhere_embeddedVariable_orderBy.
@Test
public void testWhere_embeddedVariable_orderBy() {
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*/";
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", sql.getRawSql());
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testEmbeddedVariable_containsSemicolon.
@Test
public void testEmbeddedVariable_containsSemicolon() {
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.DOMA2117, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testExpand_alias.
@Test
public void testExpand_alias() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
String testSql = "select /*%expand \"a\"*/* from aaa a";
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 a.bbb, a.ccc from aaa a", sql.getRawSql());
assertEquals("select a.bbb, a.ccc from aaa a", sql.getFormattedSql());
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testBindVariable_enum.
@Test
public void testBindVariable_enum() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(MyEnum.class, MyEnum.BBB));
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 = ? and sal = ?", sql.getRawSql());
assertEquals("select * from aaa where ename = 'BBB' and sal = 10000", sql.getFormattedSql());
assertEquals(2, sql.getParameters().size());
assertEquals(MyEnum.BBB, sql.getParameters().get(0).getWrapper().get());
assertEquals(new BigDecimal(10000), sql.getParameters().get(1).getWrapper().get());
}
Aggregations