Skip to content

Commit

Permalink
Bug 573094: Fix LTRIM/RTRIM inversion of indices
Browse files Browse the repository at this point in the history
Signed-off-by: Will Dazey <dazeydev.3@gmail.com>
  • Loading branch information
dazey3 committed May 21, 2021
1 parent 77a8c76 commit 310080a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1762,10 +1762,6 @@ public static ExpressionOperator leftTrim() {
*/
public static ExpressionOperator leftTrim2() {
ExpressionOperator operator = simpleTwoArgumentFunction(LeftTrim2, "LTRIM");

// Bug 573094
int[] indices = { 1, 0 };
operator.setArgumentIndices(indices);
return operator;
}

Expand Down Expand Up @@ -2405,10 +2401,6 @@ public static ExpressionOperator rightTrim() {
public static ExpressionOperator rightTrim2() {
// bug 2916893 rightTrim(substring) broken
ExpressionOperator operator = simpleTwoArgumentFunction(RightTrim2, "RTRIM");

// Bug 573094
int[] indices = { 1, 0 };
operator.setArgumentIndices(indices);
return operator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,6 @@ protected void initializePlatformOperators() {
addOperator(operatorLocate2());
addOperator(regexpOperator());
addOperator(exceptOperator());
addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.LeftTrim2, "LTRIM"));
addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.RightTrim2, "RTRIM"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testWhereLeftTrim() {
if(platform.isMySQL() || platform.isDB2() || platform.isDerby() || platform.isSymfoware()) {
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = TRIM(LEADING 'A' FROM 'AAHELLO WORDAAAAA'))", _sql.remove(0));
} else {
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = LTRIM('A', 'AAHELLO WORDAAAAA'))", _sql.remove(0));
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = LTRIM('AAHELLO WORDAAAAA', 'A'))", _sql.remove(0));
}

CriteriaBuilder cb = em.getCriteriaBuilder();
Expand All @@ -135,7 +135,7 @@ public void testWhereLeftTrim() {
if(platform.isMySQL() || platform.isDB2() || platform.isDerby() || platform.isSymfoware()) {
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = TRIM(LEADING 'A' FROM 'AAHELLO WORDAAAAA'))", _sql.remove(0));
} else {
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = LTRIM('A', 'AAHELLO WORDAAAAA'))", _sql.remove(0));
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = LTRIM('AAHELLO WORDAAAAA', 'A'))", _sql.remove(0));
}
} finally {
if (em.isOpen()) {
Expand All @@ -159,7 +159,7 @@ public void testWhereRightTrim() {
if(platform.isMySQL() || platform.isDB2() || platform.isDerby() || platform.isSymfoware() || platform.isHSQL() || platform instanceof FirebirdPlatform) {
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = TRIM(TRAILING 'A' FROM 'AAHELLO WORDAAAAA'))", _sql.remove(0));
} else {
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = RTRIM('A', 'AAHELLO WORDAAAAA'))", _sql.remove(0));
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = RTRIM('AAHELLO WORDAAAAA', 'A'))", _sql.remove(0));
}

CriteriaBuilder cb = em.getCriteriaBuilder();
Expand All @@ -178,7 +178,7 @@ public void testWhereRightTrim() {
if(platform.isMySQL() || platform.isDB2() || platform.isDerby() || platform.isSymfoware() || platform.isHSQL() || platform instanceof FirebirdPlatform) {
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = TRIM(TRAILING 'A' FROM 'AAHELLO WORDAAAAA'))", _sql.remove(0));
} else {
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = RTRIM('A', 'AAHELLO WORDAAAAA'))", _sql.remove(0));
Assert.assertEquals("SELECT STRVAL1 FROM TRIMENTITY WHERE (STRVAL1 = RTRIM('AAHELLO WORDAAAAA', 'A'))", _sql.remove(0));
}
} finally {
if (em.isOpen()) {
Expand Down Expand Up @@ -249,7 +249,7 @@ public void testSelectLeftTrim() {
if(platform.isMySQL() || platform.isDB2() || platform.isDerby() || platform.isSymfoware()) {
Assert.assertEquals("SELECT TRIM(LEADING 'A' FROM 'AAHELLO WORDAAAAA') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
} else {
Assert.assertEquals("SELECT LTRIM('A', 'AAHELLO WORDAAAAA') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
Assert.assertEquals("SELECT LTRIM('AAHELLO WORDAAAAA', 'A') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
}

CriteriaBuilder cb = em.getCriteriaBuilder();
Expand All @@ -268,7 +268,7 @@ public void testSelectLeftTrim() {
if(platform.isMySQL() || platform.isDB2() || platform.isDerby() || platform.isSymfoware()) {
Assert.assertEquals("SELECT TRIM(LEADING 'A' FROM 'AAHELLO WORDAAAAA') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
} else {
Assert.assertEquals("SELECT LTRIM('A', 'AAHELLO WORDAAAAA') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
Assert.assertEquals("SELECT LTRIM('AAHELLO WORDAAAAA', 'A') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
}
} finally {
if (em.isOpen()) {
Expand All @@ -292,7 +292,7 @@ public void testSelectRightTrim() {
if(platform.isMySQL() || platform.isDB2() || platform.isDerby() || platform.isSymfoware() || platform.isHSQL() || platform instanceof FirebirdPlatform) {
Assert.assertEquals("SELECT TRIM(TRAILING 'A' FROM 'AAHELLO WORDAAAAA') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
} else {
Assert.assertEquals("SELECT RTRIM('A', 'AAHELLO WORDAAAAA') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
Assert.assertEquals("SELECT RTRIM('AAHELLO WORDAAAAA', 'A') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
}

CriteriaBuilder cb = em.getCriteriaBuilder();
Expand All @@ -311,7 +311,7 @@ public void testSelectRightTrim() {
if(platform.isMySQL() || platform.isDB2() || platform.isDerby() || platform.isSymfoware() || platform.isHSQL() || platform instanceof FirebirdPlatform) {
Assert.assertEquals("SELECT TRIM(TRAILING 'A' FROM 'AAHELLO WORDAAAAA') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
} else {
Assert.assertEquals("SELECT RTRIM('A', 'AAHELLO WORDAAAAA') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
Assert.assertEquals("SELECT RTRIM('AAHELLO WORDAAAAA', 'A') FROM TRIMENTITY WHERE (STRVAL1 = 'HELLO')", _sql.remove(0));
}
} finally {
if (em.isOpen()) {
Expand Down

0 comments on commit 310080a

Please sign in to comment.