Search in sources :

Example 41 with SqlAnalyzer

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

the class BindVariableNodeTest method test_accept_inScope_notList.

public void test_accept_inScope_notList() {
    // ## Arrange ##
    String sql = "in /*pmb.memberName*/('foo', 'bar')";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("foo");
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    try {
        rootNode.accept(ctx);
        // ## Assert ##
        fail();
    } catch (BindVariableCommentInScopeNotListException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : BindVariableCommentInScopeNotListException(org.dbflute.twowaysql.exception.BindVariableCommentInScopeNotListException) CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 42 with SqlAnalyzer

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

the class BindVariableNodeTest method test_accept_number.

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

Example 43 with SqlAnalyzer

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

the class BindVariableNodeTest method test_accept_inLoopOption_default.

// ===================================================================================
// In-Loop Option
// ==============
public void test_accept_inLoopOption_default() {
    // ## Arrange ##
    String sql = "= /*FOR pmb.memberNameList*//*#current:likePrefix*/'foo'/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", "bar", "baz"));
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    rootNode.accept(ctx);
    // ## Assert ##
    assertEquals("= ???", ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 44 with SqlAnalyzer

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

the class BindVariableNodeTest method test_accept_inScope_array_string_basic.

public void test_accept_inScope_array_string_basic() {
    // ## Arrange ##
    String sql = "in /*pmb.memberNames*/('foo', 'bar')";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberNames(new String[] { "baz", "qux" });
    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("qux", ctx.getBindVariables()[1]);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 45 with SqlAnalyzer

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

the class EmbeddedVariableNodeTest method test_accept_inScope_list_integer_quoted.

public void test_accept_inScope_list_integer_quoted() {
    // ## Arrange ##
    String sql = "in /*$pmb.memberIdList*/('56', '88')";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberIdList(DfCollectionUtil.newArrayList(123, 456));
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    rootNode.accept(ctx);
    // ## Assert ##
    log("ctx:" + ctx);
    assertEquals("in ('123', '456')", ctx.getSql());
    assertEquals(0, ctx.getBindVariables().length);
}
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