|
12 | 12 | import static org.junit.jupiter.api.Assertions.*; |
13 | 13 |
|
14 | 14 | import net.sf.jsqlparser.JSQLParserException; |
| 15 | +import net.sf.jsqlparser.expression.BinaryExpression; |
15 | 16 | import net.sf.jsqlparser.expression.Expression; |
16 | 17 | import net.sf.jsqlparser.expression.StringValue; |
| 18 | +import net.sf.jsqlparser.expression.operators.conditional.AndExpression; |
17 | 19 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
| 20 | +import net.sf.jsqlparser.schema.Column; |
| 21 | +import net.sf.jsqlparser.statement.select.PlainSelect; |
18 | 22 | import net.sf.jsqlparser.test.TestUtils; |
19 | 23 | import org.junit.jupiter.api.Test; |
20 | 24 |
|
@@ -98,4 +102,87 @@ public void testMatchRegexp() throws JSQLParserException { |
98 | 102 | TestUtils.assertSqlCanBeParsedAndDeparsed( |
99 | 103 | "select * from dual where v NOT MATCH_REGEXP 'keyword1 keyword2'", true); |
100 | 104 | } |
| 105 | + |
| 106 | + @Test |
| 107 | + public void testLikeWithOldOracleJoinSyntaxOnRightOperand() throws JSQLParserException { |
| 108 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 LIKE t2.col2(+)"; |
| 109 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 110 | + LikeExpression like = (LikeExpression) select.getWhere(); |
| 111 | + |
| 112 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 113 | + ((Column) like.getRightExpression()).getOldOracleJoinSyntax()); |
| 114 | + assertEquals(EqualsTo.NO_ORACLE_JOIN, |
| 115 | + ((Column) like.getLeftExpression()).getOldOracleJoinSyntax()); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void testNotLikeWithOldOracleJoinSyntaxOnRightOperand() throws JSQLParserException { |
| 120 | + TestUtils.assertSqlCanBeParsedAndDeparsed( |
| 121 | + "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 NOT LIKE t2.col2(+)", true); |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + public void testSimilarToWithOldOracleJoinSyntaxOnRightOperand() throws JSQLParserException { |
| 126 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 SIMILAR TO t2.col2(+)"; |
| 127 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 128 | + BinaryExpression similarTo = (BinaryExpression) select.getWhere(); |
| 129 | + |
| 130 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 131 | + ((Column) similarTo.getRightExpression()).getOldOracleJoinSyntax()); |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + public void testSimilarToOnSeparateTokensWithOldOracleJoinSyntaxOnRightOperand() |
| 136 | + throws JSQLParserException { |
| 137 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 SIMILAR\nTO t2.col2(+)"; |
| 138 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 139 | + |
| 140 | + assertTrue(select.getWhere() instanceof SimilarToExpression); |
| 141 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 142 | + ((Column) ((SimilarToExpression) select.getWhere()).getRightExpression()) |
| 143 | + .getOldOracleJoinSyntax()); |
| 144 | + } |
| 145 | + |
| 146 | + @Test |
| 147 | + public void testILikeWithOldOracleJoinSyntaxOnRightOperand() throws JSQLParserException { |
| 148 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 ILIKE t2.col2(+)"; |
| 149 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 150 | + LikeExpression like = (LikeExpression) select.getWhere(); |
| 151 | + |
| 152 | + assertEquals(LikeExpression.KeyWord.ILIKE, like.getLikeKeyWord()); |
| 153 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 154 | + ((Column) like.getRightExpression()).getOldOracleJoinSyntax()); |
| 155 | + } |
| 156 | + |
| 157 | + @Test |
| 158 | + public void testLikeWithOldOracleJoinSyntaxInJoinOnClause() throws JSQLParserException { |
| 159 | + String sqlStr = |
| 160 | + "SELECT * FROM table1 t1 LEFT JOIN table2 t2 ON t1.a = t2.b AND t1.col1 LIKE t2.col2(+)"; |
| 161 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 162 | + LikeExpression like = (LikeExpression) ((AndExpression) select.getJoins().get(0) |
| 163 | + .getOnExpression()).getRightExpression(); |
| 164 | + |
| 165 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 166 | + ((Column) like.getRightExpression()).getOldOracleJoinSyntax()); |
| 167 | + } |
| 168 | + |
| 169 | + @Test |
| 170 | + public void testSimilarToWithOldOracleJoinSyntaxOnRightOperandAndEscape() |
| 171 | + throws JSQLParserException { |
| 172 | + TestUtils.assertSqlCanBeParsedAndDeparsed( |
| 173 | + "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 SIMILAR TO t2.col2(+) ESCAPE '\\'", |
| 174 | + true); |
| 175 | + } |
| 176 | + |
| 177 | + @Test |
| 178 | + public void testLikeWithOldOracleJoinSyntaxOnLeftOperand() throws JSQLParserException { |
| 179 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1(+) LIKE t2.col2"; |
| 180 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 181 | + LikeExpression like = (LikeExpression) select.getWhere(); |
| 182 | + |
| 183 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 184 | + ((Column) like.getLeftExpression()).getOldOracleJoinSyntax()); |
| 185 | + assertEquals(EqualsTo.NO_ORACLE_JOIN, |
| 186 | + ((Column) like.getRightExpression()).getOldOracleJoinSyntax()); |
| 187 | + } |
101 | 188 | } |
0 commit comments