Skip to content

Commit

Permalink
Fixes mybatis#64 <where /> does not remove the first AND or OR if it'…
Browse files Browse the repository at this point in the history
…s followed by a tab character.
harawata committed Jun 20, 2013

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 784af97 commit 30a8ba0
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
public class WhereSqlNode extends TrimSqlNode {

public WhereSqlNode(Configuration configuration, SqlNode contents) {
super(configuration, contents, "WHERE", "AND |OR |AND\n|OR\n|AND\r|OR\r", null, null);
super(configuration, contents, "WHERE", "AND |OR |AND\n|OR\n|AND\r|OR\r|AND\t|OR\t", null, null);
}


Original file line number Diff line number Diff line change
@@ -173,6 +173,19 @@ public void shouldTrimWHEREANDWithCRLFForFirstCondition() throws Exception {
assertEquals(expected, boundSql.getSql());
}

@Test
public void shouldTrimWHEREANDWithTABForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \t ID = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" and\t ID = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}

@Test
public void shouldTrimWHEREORWithLFForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \n ID = ?";
@@ -199,6 +212,19 @@ public void shouldTrimWHEREORWithCRLFForFirstCondition() throws Exception {
assertEquals(expected, boundSql.getSql());
}

@Test
public void shouldTrimWHEREORWithTABForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \t ID = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode(" or\t ID = ? ")), "true"
)
)));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}

@Test
public void shouldTrimWHEREInsteadOfORForSecondCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE NAME = ?";

0 comments on commit 30a8ba0

Please sign in to comment.