use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class EmbeddedVariableNodeTest method test_accept_null_notAllowed.
public void test_accept_null_notAllowed() {
// ## Arrange ##
String sql = "= /*$pmb.memberId*/8";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, true);
Node rootNode = analyzer.analyze();
MockMemberPmb pmb = new MockMemberPmb();
CommandContext ctx = createCtx(pmb);
// ## Act ##
try {
rootNode.accept(ctx);
// ## Assert ##
fail();
} catch (EmbeddedVariableCommentParameterNullValueException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class EmbeddedVariableNodeTest method test_accept_null_allowed.
public void test_accept_null_allowed() {
// ## Arrange ##
String sql = "= /*$pmb.memberId*/8";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
Node rootNode = analyzer.analyze();
MockMemberPmb pmb = new MockMemberPmb();
CommandContext ctx = createCtx(pmb);
// ## Act ##
rootNode.accept(ctx);
// ## Assert ##
log("ctx:" + ctx);
assertEquals("= null", ctx.getSql());
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_for_where_all_false.
public void test_parse_BEGIN_for_where_all_false() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " /*IF pmb.memberId != null*/member.MEMBER_ID = 3/*END*/";
sql = sql + " /*IF pmb.memberName != null*/and member.MEMBER_NAME = 'TEST'/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
String expected = "";
assertEquals(expected, ctx.getSql());
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_IF_notFoundProperty_with_likeSearch.
public void test_parse_BEGIN_IF_notFoundProperty_with_likeSearch() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " /*IF pmb.wrongMemberId != null*/member.MEMBER_ID = /*pmb.memberId*/3/*END*/";
sql = sql + " /*IF pmb.memberName != null*/and member.MEMBER_NAME like /*pmb.memberName*/'foo%'/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
try {
MockLikeSearchMemberPmb pmb = new MockLikeSearchMemberPmb();
Node rootNode = analyzer.analyze();
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
// ## Assert ##
fail();
} catch (IfCommentNotFoundPropertyException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_that_has_nested_IFIF_fixed_condition_.
public void test_parse_BEGIN_that_has_nested_IFIF_fixed_condition_() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " 1 = 1";
sql = sql + "/*IF pmb.memberId != null*/";
sql = sql + "and FIXED";
sql = sql + "/*END*/";
sql = sql + " ";
sql = sql + "/*IF pmb.memberName != null*/";
sql = sql + "and AAA /*IF true*/and BBB /*IF true*/and CCC/*END*//*END*/ /*IF true*/and DDD/*END*/";
sql = sql + "/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberName("foo");
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
String expected = "where 1 = 1 AAA and BBB and CCC and DDD";
// BEGIN comment does not need in this pattern
assertEquals(expected, ctx.getSql());
}
Aggregations