use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method test_analyze_IF_keepLine_if_false.
public void test_analyze_IF_keepLine_if_false() {
// ## Arrange ##
SimpleMapPmb<Object> pmb = preparePmb();
StringBuilder sb = new StringBuilder();
sb.append("select *");
sb.append(ln());
sb.append(ln()).append("/*IF pmb.sea*/mystic/*END*/");
sb.append(ln()).append("/*IF pmb.land*/");
sb.append(ln()).append("oneman");
sb.append(ln()).append("/*END*/");
sb.append(ln()).append("/*$pmb.iks*/");
String twoway = sb.toString();
SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
// ## Act ##
Node node = analyzer.analyze();
// ## Assert ##
CommandContext ctx = prepareCtx(pmb, node);
String sql = ctx.getSql();
log(ln() + sql);
assertEquals("select *\n\nmystic\n\namba", sql);
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method test_analyze_FOR_keepLine_if_false.
public void test_analyze_FOR_keepLine_if_false() {
// ## Arrange ##
StringBuilder sb = new StringBuilder();
sb.append("select *");
sb.append(ln());
sb.append(ln()).append("/*FOR pmb.bonvo*/");
sb.append(ln()).append("/*$#current*/mystic");
sb.append(ln()).append("/*END*/");
sb.append(ln()).append("/*FOR pmb.bonvo*/oneman/*END*/");
sb.append(ln()).append("/*$pmb.iks*/");
String twoway = sb.toString();
SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
// ## Act ##
Node node = analyzer.analyze();
// ## Assert ##
SimpleMapPmb<Object> pmb = preparePmb();
CommandContext ctx = prepareCtx(pmb, node);
String sql = ctx.getSql();
log(ln() + sql);
assertEquals("select *\n\n\n\namba", sql);
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method prepareCtx.
protected CommandContext prepareCtx(SimpleMapPmb<Object> pmb, Node node) {
CommandContextCreator creator = new CommandContextCreator(new String[] { "pmb" }, new Class<?>[] { pmb.getClass() });
CommandContext ctx = creator.createCommandContext(new Object[] { pmb });
node.accept(ctx);
return ctx;
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method test_analyze_bindVariable_nonSwitchToEmbedded_meansNormal.
public void test_analyze_bindVariable_nonSwitchToEmbedded_meansNormal() {
// ## Arrange ##
String twoway = "/*BEGIN*/where";
twoway = twoway + " /*IF pmb.sea*/member.MEMBER_ID = /*pmb.iks*/'abc'/*END*/";
twoway = twoway + " /*IF pmb.land*/and member.MEMBER_NAME = /*pmb.iks*/'stu'/*END*/";
twoway = twoway + " /*FOR pmb.dstore*/";
twoway = twoway + " /*#current*/mystic";
twoway = twoway + " /*END*/";
twoway = twoway + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
// ## Act ##
Node node = analyzer.analyze();
// ## Assert ##
SimpleMapPmb<Object> pmb = preparePmb();
CommandContext ctx = prepareCtx(pmb, node);
String sql = ctx.getSql();
log(ln() + sql);
String expected = "where member.MEMBER_ID = ? ? ? ";
assertEquals(expected, sql);
assertEquals(3, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method test_analyze_bindVariable_switchToEmbedded_dangerous.
public void test_analyze_bindVariable_switchToEmbedded_dangerous() {
// ## Arrange ##
String twoway = "/*BEGIN*/where";
twoway = twoway + " /*IF pmb.sea*/member.MEMBER_ID = /*pmb.iks*/'abc'/*END*/";
twoway = twoway + " /*IF pmb.land*/and member.MEMBER_NAME = /*pmb.iks*/'stu'/*END*/";
twoway = twoway + " /*FOR pmb.dstore*/";
twoway = twoway + " /*#current*/mystic";
twoway = twoway + " /*END*/";
twoway = twoway + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false).switchBindingToReplaceOnlyEmbedded();
// ## Act ##
Node node = analyzer.analyze();
// ## Assert ##
SimpleMapPmb<Object> pmb = preparePmb();
CommandContext ctx = prepareCtx(pmb, node);
String sql = ctx.getSql();
log(ln() + sql);
String expected = "where member.MEMBER_ID = 'amba''abc' unimystic citymystic ";
assertEquals(expected, sql);
assertEquals(0, ctx.getBindVariables().length);
}
Aggregations