use of org.dbflute.twowaysql.exception.ForCommentParameterNullElementException in project dbflute-core by dbflute.
the class ForNodeTest method test_accept_currentParameter_in_Bind_null_notAllowed.
public void test_accept_currentParameter_in_Bind_null_notAllowed() throws Exception {
// ## Arrange ##
MockPmb pmb = new MockPmb();
pmb.setMemberId(3);
pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", null, "baz"));
pmb.setMemberNameListInternalLikeSearchOption(new LikeSearchOption().likePrefix());
StringBuilder sb = new StringBuilder();
sb.append("select * from MEMBER").append(ln());
sb.append(" /*BEGIN*/where").append(ln());
sb.append(" /*IF pmb.memberId != null*/").append(ln());
sb.append(" MEMBER_ID = /*pmb.memberId*/").append(ln());
sb.append(" /*END*/").append(ln());
sb.append(" /*FOR pmb.memberNameList*/").append(ln());
sb.append(" and MEMBER_NAME like /*#current*/'foo%'").append(ln());
sb.append(" /*END*/").append(ln());
sb.append(" /*END*/");
SqlAnalyzer analyzer = new SqlAnalyzer(sb.toString(), true);
Node rootNode = analyzer.analyze();
CommandContext ctx = createCtx(pmb);
// ## Act ##
try {
rootNode.accept(ctx);
// ## Assert ##
fail();
} catch (ForCommentParameterNullElementException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.exception.ForCommentParameterNullElementException in project dbflute-core by dbflute.
the class ScopeNode method handleLoopElementNullParameter.
protected void handleLoopElementNullParameter(Node child, LoopInfo loopInfo) {
if (child instanceof BindVariableNode && ((BindVariableNode) child).isBlockNullParameter()) {
final Object parameter = loopInfo.getCurrentParameter();
if (parameter == null) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("The parameter in list for bind variable was null.");
br.addItem("Advice");
br.addElement("Bind variable for select does not allow null value.");
br.addElement("Confirm your target parameter in the list.");
br.addItem("Parameter List");
br.addElement(loopInfo.getParameterList());
br.addItem("Current Index");
br.addElement(loopInfo.getLoopIndex());
br.addItem("FOR Comment Expression");
br.addElement(loopInfo.getExpression());
br.addItem("Specified SQL");
br.addElement(loopInfo.getSpecifiedSql());
String msg = br.buildExceptionMessage();
throw new ForCommentParameterNullElementException(msg);
}
}
}
Aggregations