|
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; |
17 | 18 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
| 19 | +import net.sf.jsqlparser.schema.Column; |
| 20 | +import net.sf.jsqlparser.statement.select.PlainSelect; |
18 | 21 | import net.sf.jsqlparser.test.TestUtils; |
19 | 22 | import org.junit.jupiter.api.Test; |
20 | 23 |
|
@@ -98,4 +101,64 @@ public void testMatchRegexp() throws JSQLParserException { |
98 | 101 | TestUtils.assertSqlCanBeParsedAndDeparsed( |
99 | 102 | "select * from dual where v NOT MATCH_REGEXP 'keyword1 keyword2'", true); |
100 | 103 | } |
| 104 | + |
| 105 | + @Test |
| 106 | + public void testLikeWithOldOracleJoinSyntaxOnRightOperand() throws JSQLParserException { |
| 107 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 LIKE t2.col2(+)"; |
| 108 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 109 | + LikeExpression like = (LikeExpression) select.getWhere(); |
| 110 | + |
| 111 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 112 | + ((Column) like.getRightExpression()).getOldOracleJoinSyntax()); |
| 113 | + assertEquals(EqualsTo.NO_ORACLE_JOIN, |
| 114 | + ((Column) like.getLeftExpression()).getOldOracleJoinSyntax()); |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + public void testNotLikeWithOldOracleJoinSyntaxOnRightOperand() throws JSQLParserException { |
| 119 | + TestUtils.assertSqlCanBeParsedAndDeparsed( |
| 120 | + "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 NOT LIKE t2.col2(+)", true); |
| 121 | + } |
| 122 | + |
| 123 | + @Test |
| 124 | + public void testSimilarToWithOldOracleJoinSyntaxOnRightOperand() throws JSQLParserException { |
| 125 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 SIMILAR TO t2.col2(+)"; |
| 126 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 127 | + BinaryExpression similarTo = (BinaryExpression) select.getWhere(); |
| 128 | + |
| 129 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 130 | + ((Column) similarTo.getRightExpression()).getOldOracleJoinSyntax()); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void testSimilarToOnSeparateTokensWithOldOracleJoinSyntaxOnRightOperand() |
| 135 | + throws JSQLParserException { |
| 136 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 SIMILAR\nTO t2.col2(+)"; |
| 137 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 138 | + |
| 139 | + assertTrue(select.getWhere() instanceof SimilarToExpression); |
| 140 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 141 | + ((Column) ((SimilarToExpression) select.getWhere()).getRightExpression()) |
| 142 | + .getOldOracleJoinSyntax()); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + public void testLikeWithOldOracleJoinSyntaxOnRightOperandAndEscape() |
| 147 | + throws JSQLParserException { |
| 148 | + TestUtils.assertSqlCanBeParsedAndDeparsed( |
| 149 | + "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 LIKE t2.col2(+) ESCAPE '\\'", |
| 150 | + true); |
| 151 | + } |
| 152 | + |
| 153 | + @Test |
| 154 | + public void testLikeWithOldOracleJoinSyntaxOnLeftOperand() throws JSQLParserException { |
| 155 | + String sqlStr = "SELECT * FROM table1 t1, table2 t2 WHERE t1.col1(+) LIKE t2.col2"; |
| 156 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 157 | + LikeExpression like = (LikeExpression) select.getWhere(); |
| 158 | + |
| 159 | + assertEquals(EqualsTo.ORACLE_JOIN_RIGHT, |
| 160 | + ((Column) like.getLeftExpression()).getOldOracleJoinSyntax()); |
| 161 | + assertEquals(EqualsTo.NO_ORACLE_JOIN, |
| 162 | + ((Column) like.getRightExpression()).getOldOracleJoinSyntax()); |
| 163 | + } |
101 | 164 | } |
0 commit comments