use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method test_analyze_nativeBinding_overlook.
public void test_analyze_nativeBinding_overlook() {
// ## Arrange ##
SqlAnalyzer analyzer = new SqlAnalyzer("select ?", false).overlookNativeBinding();
// ## Act ##
Node node = analyzer.analyze();
// ## Assert ##
SimpleMapPmb<Object> pmb = preparePmb();
CommandContext ctx = prepareCtx(pmb, node);
String sql = ctx.getSql();
assertEquals("select ?", sql);
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method test_analyze_FOR_keepLine_if_true.
// ===================================================================================
// FOR Comment
// ===========
public void test_analyze_FOR_keepLine_if_true() {
// ## Arrange ##
SimpleMapPmb<Object> pmb = preparePmb();
StringBuilder sb = new StringBuilder();
sb.append("select *");
sb.append(ln());
sb.append(ln()).append("/*FOR pmb.dstore*/");
sb.append(ln()).append("/*$#current*/mystic");
sb.append(ln()).append("/*END*/");
sb.append(ln()).append("/*FOR pmb.dstore*/oneman/*END*/");
sb.append(ln()).append("/*$pmb.iks*/");
String twoway = sb.toString();
SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
// ## Act ##
Node node = analyzer.analyze();
// ## Assert ##
CommandContext ctx = prepareCtx(pmb, node);
String sql = ctx.getSql();
log(ln() + sql);
assertEquals("select *\n\n\nuni\n\ncity\n\nonemanoneman\namba", sql);
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method test_analyze_bindVariable_basic.
// ===================================================================================
// BindVariable Comment
// ====================
public void test_analyze_bindVariable_basic() {
// ## Arrange ##
String twoway = "/*BEGIN*/where";
twoway = twoway + " /*IF pmb.sea*/member.MEMBER_ID = /*pmb.iks*/'abc'/*END*/";
twoway = twoway + " /*IF pmb.land*/and member.MEMBER_NAME = /*pmb.iks*/'stu'/*END*/";
twoway = twoway + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
// ## Act ##
Node node = analyzer.analyze();
// ## Assert ##
SimpleMapPmb<Object> pmb = preparePmb();
CommandContext ctx = prepareCtx(pmb, node);
String sql = ctx.getSql();
log(ln() + sql);
String expected = "where member.MEMBER_ID = ? ";
assertEquals(expected, sql);
assertEquals(1, ctx.getBindVariables().length);
assertEquals("amba", ctx.getBindVariables()[0]);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_for_where_either_true_or.
public void test_parse_BEGIN_for_where_either_true_or() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " /*IF pmb.memberId != null*/member.MEMBER_ID = 3/*END*/";
sql = sql + " /*IF pmb.memberName != null*/or member.MEMBER_NAME = 'TEST'/*END*/";
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 member.MEMBER_NAME = 'TEST'";
assertEquals(expected, ctx.getSql());
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_that_has_nested_BEGIN_true.
// ===================================================================================
// Nested
// ======
public void test_parse_BEGIN_that_has_nested_BEGIN_true() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " ";
sql = sql + "/*IF pmb.memberName != null*/";
sql = sql + "FIXED";
sql = sql + "/*END*/";
sql = sql + " ";
sql = sql + "/*BEGIN*/";
sql = sql + "FIXED2 /*IF true*/and BBB/*END*/ /*IF true*/and CCC/*END*/";
sql = sql + "/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberName("foo");
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
// Basically Unsupported!
assertEquals("where FIXED FIXED2 BBB and CCC", ctx.getSql());
}
Aggregations