Skip to content

Commit 0403fdd

Browse files
author
tfedkiv
committed
added support of SELECT FROM table function (h2)
1 parent 830be49 commit 0403fdd

File tree

7 files changed

+134
-1
lines changed

7 files changed

+134
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.github.jsqlparser</groupId>
44
<artifactId>jsqlparser</artifactId>
5-
<version>0.9.5-SNAPSHOT</version>
5+
<version>0.9.888-SNAPSHOT</version>
66
<name>JSQLParser library</name>
77
<inceptionYear>2004</inceptionYear>
88
<organization>

src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ public interface FromItemVisitor {
3434
void visit(LateralSubSelect lateralSubSelect);
3535

3636
void visit(ValuesList valuesList);
37+
38+
void visit(TableFunction tableFunction);
3739
}

src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitorAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ public void visit(LateralSubSelect lateralSubSelect) {
4848
public void visit(ValuesList valuesList) {
4949

5050
}
51+
52+
@Override
53+
public void visit(TableFunction valuesList) {
54+
55+
}
5156
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2015 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.statement.select;
23+
24+
import net.sf.jsqlparser.expression.Alias;
25+
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
26+
27+
public class TableFunction implements FromItem {
28+
29+
private String name;
30+
private ExpressionList parameters;
31+
32+
/**
33+
* The name of he procedure, i.e. "UNWIND_TOP"
34+
*
35+
* @return the name of he procedure
36+
*/
37+
public String getName() {
38+
return name;
39+
}
40+
41+
public void setName(String string) {
42+
name = string;
43+
}
44+
45+
/**
46+
* The list of parameters of the tableFunction (if any, else null)
47+
*
48+
* @return the list of parameters of the tableFunction (if any, else null)
49+
*/
50+
public ExpressionList getParameters() {
51+
return parameters;
52+
}
53+
54+
public void setParameters(ExpressionList list) {
55+
parameters = list;
56+
}
57+
58+
@Override
59+
public void accept(FromItemVisitor fromItemVisitor) {
60+
fromItemVisitor.visit(this);
61+
}
62+
63+
@Override
64+
public Alias getAlias() {
65+
throw new UnsupportedOperationException();
66+
}
67+
68+
@Override
69+
public void setAlias(Alias alias) {
70+
throw new UnsupportedOperationException();
71+
}
72+
73+
@Override
74+
public Pivot getPivot() {
75+
throw new UnsupportedOperationException();
76+
}
77+
78+
@Override
79+
public void setPivot(Pivot pivot) {
80+
throw new UnsupportedOperationException();
81+
}
82+
83+
@Override
84+
public String toString() {
85+
String params;
86+
87+
if (parameters != null) {
88+
params = parameters.toString();
89+
}else {
90+
params = "()";
91+
}
92+
93+
String ans = name + "" + params + "";
94+
95+
return ans;
96+
}
97+
98+
}

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,8 @@ public void visit(Merge merge) {
640640
public void visit(OracleHint hint) {
641641
}
642642

643+
@Override
644+
public void visit(TableFunction valuesList) {
645+
}
646+
643647
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,4 +420,9 @@ public void visit(ValuesList valuesList) {
420420
public void visit(AllColumns allColumns) {
421421
buffer.append('*');
422422
}
423+
424+
@Override
425+
public void visit(TableFunction tableFunction) {
426+
buffer.append(tableFunction.toString());
427+
}
423428
}

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,9 @@ FromItem FromItem():
11001100
")"
11011101
)
11021102
|
1103+
LOOKAHEAD(TableFunction())
1104+
fromItem=TableFunction()
1105+
|
11031106
fromItem=Table()
11041107
|
11051108
fromItem=LateralSubSelect()
@@ -2414,6 +2417,22 @@ MySQLGroupConcat MySQLGroupConcat():{
24142417
}
24152418
}
24162419

2420+
TableFunction TableFunction():
2421+
{
2422+
TableFunction retval = new TableFunction();
2423+
String procName = null;
2424+
ExpressionList expressionList = null;
2425+
}
2426+
{
2427+
procName=RelObjectNameExt()
2428+
"(" [ expressionList=SimpleExpressionList() ] ")"
2429+
2430+
{
2431+
retval.setParameters(expressionList);
2432+
retval.setName(procName);
2433+
return retval;
2434+
}
2435+
}
24172436

24182437
SubSelect SubSelect():
24192438
{

0 commit comments

Comments
 (0)