use of org.dbflute.twowaysql.exception.BindVariableCommentIllegalParameterBeanSpecificationException in project dbflute-core by dbflute.
the class ForNodeTest method test_accept_FOR_spellMiss.
public void test_accept_FOR_spellMiss() throws Exception {
// ## Arrange ##
MockPmb pmb = new MockPmb();
pmb.setMemberId(3);
pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", "bar", "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(" /*FAR 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(), false);
Node rootNode = analyzer.analyze();
CommandContext ctx = createCtx(pmb);
// ## Act ##
try {
rootNode.accept(ctx);
// ## Assert ##
fail();
} catch (BindVariableCommentIllegalParameterBeanSpecificationException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.exception.BindVariableCommentIllegalParameterBeanSpecificationException in project dbflute-core by dbflute.
the class NodeChecker method throwBindOrEmbeddedCommentIllegalParameterBeanSpecificationException.
public static void throwBindOrEmbeddedCommentIllegalParameterBeanSpecificationException(String expression, String specifiedSql, boolean bind) {
final String name = (bind ? "bind variable" : "embedded variable");
final String emmark = (bind ? "" : "$");
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("The " + name + " comment had the illegal parameter-bean specification.");
br.addItem("Advice");
br.addElement("At first, is it really " + name + " comment?");
br.addElement("Have you had a spell miss?");
br.addElement("For example:");
br.addElement(" (x):");
br.addElement(" /*IE pmb...*/");
br.addElement(" /*FUOR pmb...*/");
br.addElement(" /*BIGAN*/");
br.addElement(" (o):");
br.addElement(" /*IF pmb...*/");
br.addElement(" /*FOR pmb...*/");
br.addElement(" /*BEGIN*/");
br.addElement("");
br.addElement("If you want to set " + name + "comment,");
br.addElement("confirm the spell of parameter-bean expression.");
br.addElement("(using parameter-bean, it should be named 'pmb')");
br.addElement("For example:");
br.addElement(" (x):");
br.addElement(" /*" + emmark + "pmb,memberId*/");
br.addElement(" /*" + emmark + "p mb.memberId*/");
br.addElement(" /*" + emmark + "pmb:memberId*/");
br.addElement(" /*" + emmark + "pnb.memberId*/");
br.addElement(" (o):");
br.addElement(" /*" + emmark + "pmb.memberId*/");
br.addElement("");
br.addElement("Or does it contain native binding mark '?' in your SQL?");
br.addElement("You cannot use native binding, use bind variable comment instead.");
br.addElement(" (x):");
br.addElement(" where MEMBER_ID = ? -- *NG");
br.addElement(" (o):");
br.addElement(" where MEMBER_ID = /*pmb.memberId*/ -- OK");
br.addItem("Comment Expression");
br.addElement(expression);
// *debug to this exception does not need contents of the parameter-bean
// (and for security to application data)
// br.addItem("ParameterBean");
// br.addElement(pmb);
br.addItem("Specified SQL");
br.addElement(specifiedSql);
final String msg = br.buildExceptionMessage();
if (bind) {
throw new BindVariableCommentIllegalParameterBeanSpecificationException(msg);
} else {
throw new EmbeddedVariableCommentIllegalParameterBeanSpecificationException(msg);
}
}
Aggregations