Search in sources :

Example 96 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer 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]);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 97 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.

the class BindVariableNodeTest method test_accept_null_allowed.

public void test_accept_null_allowed() {
    // ## Arrange ##
    String sql = "= /*pmb.memberId*/8";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    rootNode.accept(ctx);
    // ## Assert ##
    log("ctx:" + ctx);
    assertEquals("= ?", ctx.getSql());
    assertEquals(1, ctx.getBindVariables().length);
    assertEquals(null, ctx.getBindVariables()[0]);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 98 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer 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());
    }
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer) BindVariableCommentParameterNullValueException(org.dbflute.twowaysql.exception.BindVariableCommentParameterNullValueException)

Example 99 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.

the class EmbeddedVariableNodeTest method test_accept_string_notQuoted.

public void test_accept_string_notQuoted() {
    // ## 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("= bar", ctx.getSql());
    assertEquals(0, ctx.getBindVariables().length);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 100 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.

the class BeginNodeTest method test_parse_BEGIN_for_where_either_true_ln.

public void test_parse_BEGIN_for_where_either_true_ln() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where" + ln();
    sql = sql + " /*IF pmb.memberId != null*/" + ln();
    sql = sql + " member.MEMBER_ID = 3" + ln();
    sql = sql + " /*END*/" + ln();
    sql = sql + " /*IF pmb.memberName != null*/" + ln();
    sql = sql + " and member.MEMBER_NAME = 'TEST'" + ln();
    sql = sql + " /*END*/" + ln();
    sql = sql + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("pmb");
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    String expected = "where" + ln() + " " + ln() + " member.MEMBER_NAME = 'TEST'" + ln() + " " + ln();
    assertEquals(expected, ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Aggregations

SqlAnalyzer (org.dbflute.twowaysql.SqlAnalyzer)107 CommandContext (org.dbflute.twowaysql.context.CommandContext)99 LikeSearchOption (org.dbflute.cbean.coption.LikeSearchOption)33 List (java.util.List)5 EndCommentNotFoundException (org.dbflute.twowaysql.exception.EndCommentNotFoundException)3 IfCommentNotFoundPropertyException (org.dbflute.twowaysql.exception.IfCommentNotFoundPropertyException)3 MelodicNodeAdviceFactory (org.dbflute.bhv.core.melodicsql.MelodicNodeAdviceFactory)2 EmbeddedVariableCommentContainsBindSymbolException (org.dbflute.twowaysql.exception.EmbeddedVariableCommentContainsBindSymbolException)2 CommentTerminatorNotFoundException (org.dbflute.exception.CommentTerminatorNotFoundException)1 CommandContextCreator (org.dbflute.twowaysql.context.CommandContextCreator)1 BindVariableCommentIllegalParameterBeanSpecificationException (org.dbflute.twowaysql.exception.BindVariableCommentIllegalParameterBeanSpecificationException)1 BindVariableCommentInScopeNotListException (org.dbflute.twowaysql.exception.BindVariableCommentInScopeNotListException)1 BindVariableCommentParameterNullValueException (org.dbflute.twowaysql.exception.BindVariableCommentParameterNullValueException)1 EmbeddedVariableCommentInScopeNotListException (org.dbflute.twowaysql.exception.EmbeddedVariableCommentInScopeNotListException)1 EmbeddedVariableCommentParameterNullValueException (org.dbflute.twowaysql.exception.EmbeddedVariableCommentParameterNullValueException)1 ForCommentParameterNullElementException (org.dbflute.twowaysql.exception.ForCommentParameterNullElementException)1 IfCommentConditionEmptyException (org.dbflute.twowaysql.exception.IfCommentConditionEmptyException)1 InLoopOptionOutOfLoopException (org.dbflute.twowaysql.exception.InLoopOptionOutOfLoopException)1 LoopCurrentVariableOutOfForCommentException (org.dbflute.twowaysql.exception.LoopCurrentVariableOutOfForCommentException)1 SqlAnalyzerFactory (org.dbflute.twowaysql.factory.SqlAnalyzerFactory)1