use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BindVariableNodeTest method test_accept_inLoopOption_outOfLoop.
public void test_accept_inLoopOption_outOfLoop() {
// ## Arrange ##
String sql = "= /*pmb.memberName:notLike*/'foo'";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
Node rootNode = analyzer.analyze();
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberName("bar");
CommandContext ctx = createCtx(pmb);
// ## Act ##
try {
rootNode.accept(ctx);
// ## Assert ##
fail();
} catch (InLoopOptionOutOfLoopException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BindVariableNodeTest 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 (BindVariableCommentParameterNullValueException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BindVariableNodeTest method test_accept_inLoopOption_melodic.
public void test_accept_inLoopOption_melodic() {
// ## Arrange ##
String sql = "= /*FOR pmb.memberNameList*//*#current:likePrefix*/'foo'/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false) {
@Override
protected NodeAdviceFactory getNodeAdviceFactory() {
return new MelodicNodeAdviceFactory();
}
};
Node rootNode = analyzer.analyze();
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", "bar", "baz"));
CommandContext ctx = createCtx(pmb);
// ## Act ##
rootNode.accept(ctx);
// ## Assert ##
log("ctx:" + ctx);
assertEquals("= ? escape '|' ? escape '|' ? escape '|' ", ctx.getSql());
assertEquals(3, ctx.getBindVariables().length);
assertEquals("foo%", ctx.getBindVariables()[0]);
assertEquals("bar%", ctx.getBindVariables()[1]);
assertEquals("baz%", ctx.getBindVariables()[2]);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BindVariableNodeTest method test_accept_inScope_bindSymbol.
public void test_accept_inScope_bindSymbol() {
// ## Arrange ##
String sql = "in /*pmb.memberNameList*/('foo', 'bar')";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
Node rootNode = analyzer.analyze();
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberNameList(DfCollectionUtil.newArrayList("baz", "q?ux"));
CommandContext ctx = createCtx(pmb);
// ## Act ##
rootNode.accept(ctx);
// ## Assert ##
log("ctx:" + ctx);
assertEquals("in (?, ?)", ctx.getSql());
assertEquals(2, ctx.getBindVariables().length);
assertEquals("baz", ctx.getBindVariables()[0]);
assertEquals("q?ux", ctx.getBindVariables()[1]);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BindVariableNodeTest method test_accept_string.
public void test_accept_string() {
// ## Arrange ##
String sql = "= /*pmb.memberName*/'foo'";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
Node rootNode = analyzer.analyze();
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberName("bar");
CommandContext ctx = createCtx(pmb);
// ## Act ##
rootNode.accept(ctx);
// ## Assert ##
log("ctx:" + ctx);
assertEquals("= ?", ctx.getSql());
assertEquals(1, ctx.getBindVariables().length);
assertEquals("bar", ctx.getBindVariables()[0]);
}
Aggregations