Skip to content

Commit 8ac250d

Browse files
committed
corrected some sql test scripts to be deparseable
corrected pivot handling in SelectDeParser
1 parent a626532 commit 8ac250d

File tree

15 files changed

+49
-42
lines changed

15 files changed

+49
-42
lines changed

nb-configuration.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project-shared-configuration>
3-
<!--
3+
<!--
44
This file contains additional configuration written by modules in the NetBeans IDE.
55
The configuration is intended to be shared among all the users of project and
66
therefore it is assumed to be part of version control checkout.
77
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
88
-->
9-
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
10-
<!--
9+
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
10+
<!--
1111
Properties that influence various parts of the IDE, especially code formatting and the like.
1212
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
1313
That way multiple projects can share the same settings (useful for formatting rules for example).
1414
Any value defined here will override the pom.xml file value but is only applicable to the current project.
1515
-->
16-
<netbeans.compile.on.save>none</netbeans.compile.on.save>
17-
</properties>
16+
<netbeans.compile.on.save>all</netbeans.compile.on.save>
17+
</properties>
1818
</project-shared-configuration>

src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void visit(PlainSelect plainSelect) {
9696
buffer.append(" WHERE ");
9797
plainSelect.getWhere().accept(expressionVisitor);
9898
}
99-
99+
100100
if (plainSelect.getOracleHierarchical() != null) {
101101
plainSelect.getOracleHierarchical().accept(expressionVisitor);
102102
}
@@ -276,6 +276,10 @@ public void visit(SubJoin subjoin) {
276276
subjoin.getLeft().accept(this);
277277
deparseJoin(subjoin.getJoin());
278278
buffer.append(")");
279+
280+
if (subjoin.getPivot() != null) {
281+
subjoin.getPivot().accept(this);
282+
}
279283
}
280284

281285
public void deparseJoin(Join join) {

src/test/java/net/sf/jsqlparser/test/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void assertStatementCanBeDeparsedAs(Statement parsed, String state
6868

6969
public static String buildSqlString(String sql, boolean laxDeparsingCheck) {
7070
if (laxDeparsingCheck) {
71-
return sql.replaceAll("\\s", " ").replaceAll("\\s+", " ").replaceAll("\\s*([,()=+\\-*|\\]<>])\\s*", "$1").toLowerCase().trim();
71+
return sql.replaceAll("\\s", " ").replaceAll("\\s+", " ").replaceAll("\\s*([/,()=+\\-*|\\]<>])\\s*", "$1").toLowerCase().trim();
7272
} else {
7373
return sql;
7474
}

src/test/java/net/sf/jsqlparser/test/select/SpecialOracleTests.java renamed to src/test/java/net/sf/jsqlparser/test/select/SpecialOracleTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@
2626
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
2727
import static net.sf.jsqlparser.test.TestUtils.*;
2828
import org.apache.commons.io.FileUtils;
29+
import static org.junit.Assert.assertTrue;
2930
import org.junit.Test;
3031

3132
/**
3233
* Tries to parse and deparse all statments in
3334
* net.sf.jsqlparser.test.oracle-tests.
35+
*
36+
* As a matter of fact there are a lot of files that can still not processed.
37+
* Here a step by step improvement is the way to go.
38+
*
39+
* The test ensures, that the successfull parsed file count does not decrease.
3440
*
3541
* @author toben
3642
*/
37-
public class SpecialOracleTests {
43+
public class SpecialOracleTest {
3844

3945
private static final File SQLS_DIR = new File("target/test-classes/net/sf/jsqlparser/test/oracle-tests");
40-
private static final Logger LOG = Logger.getLogger(SpecialOracleTests.class.getName());
46+
private static final Logger LOG = Logger.getLogger(SpecialOracleTest.class.getName());
4147

4248
@Test
4349
public void testAllSqlsParseDeparse() throws IOException {
@@ -61,6 +67,7 @@ public void testAllSqlsParseDeparse() throws IOException {
6167
}
6268

6369
LOG.log(Level.INFO, "tested {0} files. got {1} correct parse results", new Object[]{count, success});
70+
assertTrue(success>100);
6471
}
6572

6673
@Test

src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring01.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
with
22
reports_to_101 (eid, emp_last, mgr_id, reportlevel) as
33
(
4-
select employee_id, last_name, manager_id, 0 reportlevel
4+
(select employee_id, last_name, manager_id, 0 reportlevel
55
from employees
6-
where employee_id = 101
6+
where employee_id = 101)
77
union all
8-
select e.employee_id, e.last_name, e.manager_id, reportlevel+1
8+
(select e.employee_id, e.last_name, e.manager_id, reportlevel+1
99
from reports_to_101 r, employees e
10-
where r.eid = e.manager_id
10+
where r.eid = e.manager_id)
1111
)
1212
select eid, emp_last, mgr_id, reportlevel
1313
from reports_to_101 r, auto a

src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring02.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ with
22
reports_to_101 (eid, emp_last, mgr_id, reportlevel, mgr_list)
33
as
44
(
5-
select employee_id, last_name, manager_id, 0 reportlevel
5+
(select employee_id, last_name, manager_id, 0 reportlevel
66
, cast(manager_id as varchar2(2000))
77
from employees
8-
where employee_id = 101
8+
where employee_id = 101)
99
union all
10-
select e.employee_id, e.last_name, e.manager_id, reportlevel+1
10+
(select e.employee_id, e.last_name, e.manager_id, reportlevel+1
1111
, cast(mgr_list || ',' || manager_id as varchar2(2000))
1212
from reports_to_101 r, employees e
13-
where r.eid = e.manager_id
13+
where r.eid = e.manager_id)
1414
)
1515
select eid, emp_last, mgr_id, reportlevel, mgr_list
1616
from reports_to_101

src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring03.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
with
22
reports_to_101 (eid, emp_last, mgr_id, reportlevel) as
33
(
4-
select employee_id, last_name, manager_id, 0 reportlevel
4+
(select employee_id, last_name, manager_id, 0 reportlevel
55
from employees
6-
where employee_id = 101
6+
where employee_id = 101)
77
union all
8-
select e.employee_id, e.last_name, e.manager_id, reportlevel+1
8+
(select e.employee_id, e.last_name, e.manager_id, reportlevel+1
99
from reports_to_101 r, employees e
10-
where r.eid = e.manager_id
10+
where r.eid = e.manager_id)
1111
)
1212
select eid, emp_last, mgr_id, reportlevel
1313
from reports_to_101

src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring04.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
with
22
org_chart (eid, emp_last, mgr_id, reportlevel, salary, job_id) as
33
(
4-
select employee_id, last_name, manager_id, 0 reportlevel, salary, job_id
4+
(select employee_id, last_name, manager_id, 0 reportlevel, salary, job_id
55
from employees
6-
where manager_id is null
6+
where manager_id is null)
77
union all
8-
select e.employee_id, e.last_name, e.manager_id,
8+
(select e.employee_id, e.last_name, e.manager_id,
99
r.reportlevel+1 reportlevel, e.salary, e.job_id
1010
from org_chart r, employees e
11-
where r.eid = e.manager_id
11+
where r.eid = e.manager_id)
1212
)
1313
search depth first by emp_last set order1
1414
select lpad(' ',2*reportlevel)||emp_last emp_name, eid, mgr_id, salary, job_id

src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring08.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
with -- qf
1+
with
22
x1 as ( select * from t1 ),
33
x2 as ( select * from t2 join t3 on (t2.a2 = t3.a3))
44
select
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
select 'a' obj, 'b' link from dual union all
2-
select 'a', 'c' from dual union all
3-
select 'c', 'd' from dual union all
4-
select 'd', 'c' from dual union all
5-
select 'd', 'e' from dual union all
6-
select 'e', 'e' from dual
1+
(select 'a' obj, 'b' link from dual) union all
2+
(select 'a', 'c' from dual) union all
3+
(select 'c', 'd' from dual) union all
4+
(select 'd', 'c' from dual) union all
5+
(select 'd', 'e' from dual) union all
6+
(select 'e', 'e' from dual)
77

0 commit comments

Comments
 (0)