use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testWhere.
@Test
public void testWhere() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
String testSql = "select * from aaa where /*%if false*/ename = 'aaa'/*%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());
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testIf.
@Test
public void testIf() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
String testSql = "select * from aaa where /*%if name != null*/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.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testFor.
@Test
public void testFor() {
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*/'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.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testBindVariable_floatLiteral.
@Test
public void testBindVariable_floatLiteral() {
String testSql = "select * from aaa where ename = /*name*/.0";
SqlParser parser = new SqlParser(testSql);
SqlNode node = parser.parse();
assertNotNull(node);
}
use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.
the class SqlParserTest method testFor_removeWhere.
@Test
public void testFor_removeWhere() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
ArrayList<String> list = new ArrayList<>();
evaluator.add("names", new Value(List.class, list));
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", sql.getRawSql());
assertEquals("select * from aaa", sql.getFormattedSql());
assertEquals(0, sql.getParameters().size());
}
Aggregations