|
9 | 9 | */ |
10 | 10 | package net.sf.jsqlparser.statement.select; |
11 | 11 |
|
| 12 | +import java.util.logging.Logger; |
12 | 13 | import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; |
13 | 14 | import org.junit.Ignore; |
14 | 15 | import org.junit.Test; |
@@ -48,29 +49,57 @@ public void testIssue856() throws JSQLParserException { |
48 | 49 | String sql = "SELECT " + buildRecursiveBracketExpression("if(month(today()) = 3, sum(\"Table5\".\"Month 002\"), $1)", "0", 5) + " FROM mytbl"; |
49 | 50 | assertSqlCanBeParsedAndDeparsed(sql); |
50 | 51 | } |
51 | | - |
| 52 | + |
52 | 53 | @Test |
53 | 54 | public void testRecursiveBracketExpressionIssue1019() { |
54 | 55 | assertEquals("IF(1=1, 1, 2)", buildRecursiveBracketExpression("IF(1=1, $1, 2)", "1", 0)); |
55 | 56 | assertEquals("IF(1=1, IF(1=1, 1, 2), 2)", buildRecursiveBracketExpression("IF(1=1, $1, 2)", "1", 1)); |
56 | 57 | assertEquals("IF(1=1, IF(1=1, IF(1=1, 1, 2), 2), 2)", buildRecursiveBracketExpression("IF(1=1, $1, 2)", "1", 2)); |
57 | 58 | } |
58 | | - |
| 59 | + |
59 | 60 | @Test |
60 | 61 | public void testRecursiveBracketExpressionIssue1019_2() throws JSQLParserException { |
61 | 62 | doIncreaseOfParseTimeTesting("IF(1=1, $1, 2)", "1", 10); |
62 | 63 | } |
63 | 64 |
|
| 65 | + @Test |
| 66 | + public void testIssue1013() throws JSQLParserException { |
| 67 | + assertSqlCanBeParsedAndDeparsed("SELECT ((((((((((((((((tblA)))))))))))))))) FROM mytable"); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + public void testIssue1013_2() throws JSQLParserException { |
| 72 | + assertSqlCanBeParsedAndDeparsed("SELECT * FROM ((((((((((((((((tblA))))))))))))))))"); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testIssue1013_3() throws JSQLParserException { |
| 77 | + assertSqlCanBeParsedAndDeparsed("SELECT * FROM (((tblA)))"); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testIssue1013_4() throws JSQLParserException { |
| 82 | + String s = "tblA"; |
| 83 | + for (int i = 1; i < 100; i++) { |
| 84 | + s = "(" + s + ")"; |
| 85 | + } |
| 86 | + String sql = "SELECT * FROM " + s; |
| 87 | + LOG.info("testing " + sql); |
| 88 | + assertSqlCanBeParsedAndDeparsed(sql); |
| 89 | + } |
| 90 | + private static final Logger LOG = Logger.getLogger(NestedBracketsPerformanceTest.class.getName()); |
| 91 | + |
64 | 92 | /** |
65 | | - * Try to avoid or border exceptionally big parsing time increments by adding more bracket constructs. |
| 93 | + * Try to avoid or border exceptionally big parsing time increments by |
| 94 | + * adding more bracket constructs. |
66 | 95 | * |
67 | 96 | * @throws JSQLParserException |
68 | 97 | */ |
69 | 98 | @Test |
70 | 99 | public void testIncreaseOfParseTime() throws JSQLParserException { |
71 | 100 | doIncreaseOfParseTimeTesting("concat($1,'B')", "'A'", 20); |
72 | 101 | } |
73 | | - |
| 102 | + |
74 | 103 | private void doIncreaseOfParseTimeTesting(String template, String finalExpression, int maxDepth) throws JSQLParserException { |
75 | 104 | long oldDurationTime = 1000; |
76 | 105 | int countProblematic = 0; |
@@ -100,7 +129,7 @@ public void testRecursiveBracketExpression() { |
100 | 129 | assertEquals("concat(concat('A','B'),'B')", buildRecursiveBracketExpression("concat($1,'B')", "'A'", 1)); |
101 | 130 | assertEquals("concat(concat(concat('A','B'),'B'),'B')", buildRecursiveBracketExpression("concat($1,'B')", "'A'", 2)); |
102 | 131 | } |
103 | | - |
| 132 | + |
104 | 133 | private String buildRecursiveBracketExpression(String template, String finalExpression, int depth) { |
105 | 134 | if (depth == 0) { |
106 | 135 | return template.replace("$1", finalExpression); |
|
0 commit comments