Search in sources :

Example 1 with SqlNode

use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.

the class SqlParserTest method testParens_removeAnd.

@Test
public void testParens_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*/\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 ddd is null\n )", sql.getRawSql());
    assertEquals("select * from aaa where (\n\n ddd is null\n )", sql.getFormattedSql());
    assertEquals(0, sql.getParameters().size());
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) Value(org.seasar.doma.internal.expr.Value) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 2 with SqlNode

use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.

the class SqlParserTest method testEmptyParens_whiteSpace.

@Test
public void testEmptyParens_whiteSpace() {
    ExpressionEvaluator evaluator = new ExpressionEvaluator();
    SqlParser parser = new SqlParser("select rank(   )");
    SqlNode sqlNode = parser.parse();
    PreparedSql sql = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED).build(sqlNode, Function.identity());
    assertEquals("select rank(   )", sql.getRawSql());
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 3 with SqlNode

use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.

the class SqlParserTest method testBindVariable_booleanFalseLiteral.

@Test
public void testBindVariable_booleanFalseLiteral() {
    String testSql = "select * from aaa where ename = /*name*/false";
    SqlParser parser = new SqlParser(testSql);
    SqlNode node = parser.parse();
    assertNotNull(node);
}
Also used : SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 4 with SqlNode

use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.

the class SqlParserTest method testIf_removeWhere.

@Test
public void testIf_removeWhere() {
    ExpressionEvaluator evaluator = new ExpressionEvaluator();
    evaluator.add("name", new Value(String.class, null));
    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", sql.getRawSql());
    assertEquals("select * from aaa", sql.getFormattedSql());
    assertEquals(0, sql.getParameters().size());
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) Value(org.seasar.doma.internal.expr.Value) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 5 with SqlNode

use of org.seasar.doma.jdbc.SqlNode in project doma by domaframework.

the class SqlParserTest method testBindVariable_in_empty_iterable.

@Test
public void testBindVariable_in_empty_iterable() {
    ExpressionEvaluator evaluator = new ExpressionEvaluator();
    evaluator.add("name", new Value(List.class, Collections.emptyList()));
    String testSql = "select * from aaa where ename in /*name*/('aaa', '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 * from aaa where ename in (null)", sql.getRawSql());
    assertEquals("select * from aaa where ename in (null)", sql.getFormattedSql());
    assertEquals(0, sql.getParameters().size());
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) Value(org.seasar.doma.internal.expr.Value) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Aggregations

SqlNode (org.seasar.doma.jdbc.SqlNode)176 Test (org.junit.jupiter.api.Test)145 PreparedSql (org.seasar.doma.jdbc.PreparedSql)102 SqlParser (org.seasar.doma.internal.jdbc.sql.SqlParser)90 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)62 NodePreparedSqlBuilder (org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder)62 ExpressionEvaluator (org.seasar.doma.internal.expr.ExpressionEvaluator)48 Value (org.seasar.doma.internal.expr.Value)44 LinkedHashMap (java.util.LinkedHashMap)25 ExecutableElement (javax.lang.model.element.ExecutableElement)25 TestProcessor (org.seasar.doma.internal.apt.TestProcessor)25 JdbcException (org.seasar.doma.jdbc.JdbcException)20 List (java.util.List)17 BigDecimal (java.math.BigDecimal)13 ArrayList (java.util.ArrayList)12 FragmentNode (org.seasar.doma.internal.jdbc.sql.node.FragmentNode)11 SelectStatementNode (org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode)11 AptException (org.seasar.doma.internal.apt.AptException)8 OrderByClauseNode (org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode)8 WordNode (org.seasar.doma.internal.jdbc.sql.node.WordNode)6