use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_for_select_all_true.
public void test_parse_BEGIN_for_select_all_true() {
// ## Arrange ##
String sql = "select /*BEGIN*/";
sql = sql + "/*IF pmb.memberId != null*/member.MEMBER_ID as c1/*END*/";
sql = sql + "/*IF pmb.memberName != null*/, member.MEMBER_NAME as c2/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberId(3);
pmb.setMemberName("foo");
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
String expected = "select member.MEMBER_ID as c1, member.MEMBER_NAME as c2";
assertEquals(expected, ctx.getSql());
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_where_upperCase_that_has_nested_IFIF_root_has_and.
// ===================================================================================
// UpperCase
// =========
public void test_parse_BEGIN_where_upperCase_that_has_nested_IFIF_root_has_and() {
// ## Arrange ##
String sql = "/*BEGIN*/WHERE";
sql = sql + " ";
sql = sql + "/*IF pmb.memberId != null*/";
sql = sql + "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 AAA AND BBB AND CCC AND DDD";
assertEquals(expected, ctx.getSql());
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_where_upperCase_that_has_nested_IFIF_root_has_or.
// ===================================================================================
// OR
// ==
public void test_parse_BEGIN_where_upperCase_that_has_nested_IFIF_root_has_or() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " ";
sql = sql + "/*IF pmb.memberId != null*/";
sql = sql + "FIXED";
sql = sql + "/*END*/";
sql = sql + " ";
sql = sql + "/*IF pmb.memberName != null*/";
sql = sql + "or AAA /*IF true*/and BBB /*IF true*/OR CCC/*END*//*END*/ /*IF true*/or 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 AAA and BBB OR CCC or DDD";
assertEquals(expected, ctx.getSql());
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_not_adjustConnector_direct.
public void test_parse_BEGIN_not_adjustConnector_direct() {
// ## Arrange ##
String sql = "select /*BEGIN*/, ";
sql = sql + "/*IF pmb.memberId != null*/member.MEMBER_ID as c1/*END*/";
sql = sql + "/*IF pmb.memberName != null*/, member.MEMBER_NAME as c2/*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 = "select , member.MEMBER_NAME as c2";
assertEquals(expected, ctx.getSql());
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_that_has_nested_BEGIN_self_and_adjustment.
public void test_parse_BEGIN_that_has_nested_BEGIN_self_and_adjustment() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " ";
sql = sql + "/*IF pmb.memberName != null*/";
sql = sql + "FIXED";
sql = sql + "/*END*/";
sql = sql + " ";
sql = sql + "/*BEGIN*/";
sql = sql + "and FIXED2 /*IF false*/and BBB/*END*/ /*IF true*/and CCC/*END*/";
sql = sql + "/*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);
// Basically Unsupported!
assertEquals("where FIXED2 CCC", ctx.getSql());
}
Aggregations