Skip to content

Commit d1e7185

Browse files
author
Pap Lőrinc
committed
Corrected the signed expression behaviors and renamed InverseExpression to SignedExpression;
1 parent 5d151c7 commit d1e7185

File tree

6 files changed

+161
-176
lines changed

6 files changed

+161
-176
lines changed

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* Copyright (C) 2004 - 2013 JSQLParser
66
* %%
77
* 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
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
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Lesser Public License for more details.
16-
*
17-
* You should have received a copy of the GNU General Lesser Public
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
2020
* #L%
@@ -54,11 +54,11 @@ public interface ExpressionVisitor {
5454

5555
void visit(Function function);
5656

57-
void visit(InverseExpression inverseExpression);
57+
void visit(SignedExpression signedExpression);
5858

5959
void visit(JdbcParameter jdbcParameter);
60-
61-
void visit(JdbcNamedParameter jdbcNamedParameter);
60+
61+
void visit(JdbcNamedParameter jdbcNamedParameter);
6262

6363
void visit(DoubleValue doubleValue);
6464

@@ -137,10 +137,10 @@ public interface ExpressionVisitor {
137137
void visit(AnalyticExpression aexpr);
138138

139139
void visit(ExtractExpression eexpr);
140-
140+
141141
void visit(IntervalExpression iexpr);
142-
142+
143143
void visit(OracleHierarchicalExpression oexpr);
144-
144+
145145
void visit(RegExpMatchOperator rexpr);
146146
}

src/main/java/net/sf/jsqlparser/expression/InverseExpression.java renamed to src/main/java/net/sf/jsqlparser/expression/SignedExpression.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,44 @@
55
* Copyright (C) 2004 - 2013 JSQLParser
66
* %%
77
* 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
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
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Lesser Public License for more details.
16-
*
17-
* You should have received a copy of the GNU General Lesser Public
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
2020
* #L%
2121
*/
2222
package net.sf.jsqlparser.expression;
2323

2424
/**
25-
* It represents a "-" before an expression
25+
* It represents a "-" or "+" before an expression
2626
*/
27-
public class InverseExpression implements Expression {
27+
public class SignedExpression implements Expression {
2828

29-
private Expression expression;
29+
private char sign;
30+
private Expression expression;
3031

31-
public InverseExpression() {
32+
public SignedExpression(char sign, Expression expression) {
33+
this.sign = sign;
34+
setExpression(expression);
3235
}
3336

34-
public InverseExpression(Expression expression) {
35-
setExpression(expression);
36-
}
37+
public char getSign() {
38+
return sign;
39+
}
40+
41+
public void setSign(char sign) {
42+
this.sign = sign;
43+
}
3744

38-
public Expression getExpression() {
45+
public Expression getExpression() {
3946
return expression;
4047
}
4148

@@ -47,4 +54,9 @@ public final void setExpression(Expression expression) {
4754
public void accept(ExpressionVisitor expressionVisitor) {
4855
expressionVisitor.visit(this);
4956
}
57+
58+
@Override
59+
public String toString() {
60+
return getSign() + expression.toString();
61+
}
5062
}

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

Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,93 +5,38 @@
55
* Copyright (C) 2004 - 2013 JSQLParser
66
* %%
77
* 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
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
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Lesser Public License for more details.
16-
*
17-
* You should have received a copy of the GNU General Lesser Public
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
2020
* #L%
2121
*/
2222
package net.sf.jsqlparser.util;
2323

24-
import java.util.ArrayList;
25-
import java.util.List;
26-
import net.sf.jsqlparser.expression.AllComparisonExpression;
27-
import net.sf.jsqlparser.expression.AnalyticExpression;
28-
import net.sf.jsqlparser.expression.AnyComparisonExpression;
29-
import net.sf.jsqlparser.expression.BinaryExpression;
30-
import net.sf.jsqlparser.expression.CaseExpression;
31-
import net.sf.jsqlparser.expression.CastExpression;
32-
import net.sf.jsqlparser.expression.DateValue;
33-
import net.sf.jsqlparser.expression.DoubleValue;
34-
import net.sf.jsqlparser.expression.Expression;
35-
import net.sf.jsqlparser.expression.ExpressionVisitor;
36-
import net.sf.jsqlparser.expression.ExtractExpression;
37-
import net.sf.jsqlparser.expression.Function;
38-
import net.sf.jsqlparser.expression.IntervalExpression;
39-
import net.sf.jsqlparser.expression.InverseExpression;
40-
import net.sf.jsqlparser.expression.JdbcNamedParameter;
41-
import net.sf.jsqlparser.expression.JdbcParameter;
42-
import net.sf.jsqlparser.expression.LongValue;
43-
import net.sf.jsqlparser.expression.NullValue;
44-
import net.sf.jsqlparser.expression.OracleHierarchicalExpression;
45-
import net.sf.jsqlparser.expression.Parenthesis;
46-
import net.sf.jsqlparser.expression.StringValue;
47-
import net.sf.jsqlparser.expression.TimeValue;
48-
import net.sf.jsqlparser.expression.TimestampValue;
49-
import net.sf.jsqlparser.expression.WhenClause;
50-
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
51-
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
52-
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
53-
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
54-
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
55-
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
56-
import net.sf.jsqlparser.expression.operators.arithmetic.Modulo;
57-
import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication;
58-
import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction;
24+
import net.sf.jsqlparser.expression.*;
25+
import net.sf.jsqlparser.expression.operators.arithmetic.*;
5926
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
6027
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
61-
import net.sf.jsqlparser.expression.operators.relational.Between;
62-
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
63-
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
64-
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
65-
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
66-
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
67-
import net.sf.jsqlparser.expression.operators.relational.InExpression;
68-
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
69-
import net.sf.jsqlparser.expression.operators.relational.ItemsListVisitor;
70-
import net.sf.jsqlparser.expression.operators.relational.LikeExpression;
71-
import net.sf.jsqlparser.expression.operators.relational.Matches;
72-
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
73-
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
74-
import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList;
75-
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
76-
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
28+
import net.sf.jsqlparser.expression.operators.relational.*;
7729
import net.sf.jsqlparser.schema.Column;
7830
import net.sf.jsqlparser.schema.Table;
7931
import net.sf.jsqlparser.statement.delete.Delete;
8032
import net.sf.jsqlparser.statement.insert.Insert;
8133
import net.sf.jsqlparser.statement.replace.Replace;
82-
import net.sf.jsqlparser.statement.select.FromItemVisitor;
83-
import net.sf.jsqlparser.statement.select.Join;
84-
import net.sf.jsqlparser.statement.select.LateralSubSelect;
85-
import net.sf.jsqlparser.statement.select.PlainSelect;
86-
import net.sf.jsqlparser.statement.select.Select;
87-
import net.sf.jsqlparser.statement.select.SelectVisitor;
88-
import net.sf.jsqlparser.statement.select.SetOperationList;
89-
import net.sf.jsqlparser.statement.select.SubJoin;
90-
import net.sf.jsqlparser.statement.select.SubSelect;
91-
import net.sf.jsqlparser.statement.select.ValuesList;
92-
import net.sf.jsqlparser.statement.select.WithItem;
34+
import net.sf.jsqlparser.statement.select.*;
9335
import net.sf.jsqlparser.statement.update.Update;
9436

37+
import java.util.ArrayList;
38+
import java.util.List;
39+
9540
/**
9641
* Find all used tables within an select statement.
9742
*/
@@ -297,8 +242,8 @@ public void visit(InExpression inExpression) {
297242
}
298243

299244
@Override
300-
public void visit(InverseExpression inverseExpression) {
301-
inverseExpression.getExpression().accept(this);
245+
public void visit(SignedExpression signedExpression) {
246+
signedExpression.getExpression().accept(this);
302247
}
303248

304249
@Override
@@ -393,7 +338,7 @@ public void visit(TimeValue timeValue) {
393338

394339
/*
395340
* (non-Javadoc)
396-
*
341+
*
397342
* @see net.sf.jsqlparser.expression.ExpressionVisitor#visit(net.sf.jsqlparser.expression.CaseExpression)
398343
*/
399344
@Override
@@ -402,7 +347,7 @@ public void visit(CaseExpression caseExpression) {
402347

403348
/*
404349
* (non-Javadoc)
405-
*
350+
*
406351
* @see net.sf.jsqlparser.expression.ExpressionVisitor#visit(net.sf.jsqlparser.expression.WhenClause)
407352
*/
408353
@Override

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* Copyright (C) 2004 - 2013 JSQLParser
66
* %%
77
* 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
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
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Lesser Public License for more details.
16-
*
17-
* You should have received a copy of the GNU General Lesser Public
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
2020
* #L%
@@ -159,9 +159,9 @@ public void visit(InExpression inExpression) {
159159
}
160160

161161
@Override
162-
public void visit(InverseExpression inverseExpression) {
163-
buffer.append("-");
164-
inverseExpression.getExpression().accept(this);
162+
public void visit(SignedExpression signedExpression) {
163+
buffer.append(signedExpression.getSign());
164+
signedExpression.getExpression().accept(this);
165165
}
166166

167167
@Override

src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ Insert Insert():
369369
[LOOKAHEAD(2) "(" ]
370370
(
371371
{ insert.setUseValues(false); }
372-
itemsList = SubSelect()
372+
itemsList= SubSelect()
373373
)
374374
[ ")" ]
375375
)
@@ -419,7 +419,7 @@ Column Column():
419419
} else {
420420
table = new Table(null, null);
421421
colName = name1;
422-
}
422+
}
423423

424424
return new Column(table, colName);
425425
}
@@ -1585,7 +1585,7 @@ Expression PrimaryExpression():
15851585
Expression retval = null;
15861586
CastExpression castExpr = null;
15871587
Token token = null;
1588-
boolean isInverse = false;
1588+
Token sign = null;
15891589
String tmp = "";
15901590
ColDataType type = null;
15911591
}
@@ -1603,27 +1603,28 @@ Expression PrimaryExpression():
16031603

16041604
| LOOKAHEAD(ExtractExpression()) retval=ExtractExpression()
16051605

1606-
| LOOKAHEAD([ "+" | "-"] Function()) [ "+" | "-" { isInverse = true; }] retval=Function()
1606+
| LOOKAHEAD(["+" | "-"] Function()) [sign="+" | sign="-"] retval=Function()
16071607

1608-
| LOOKAHEAD([ "+" | "-"] <S_DOUBLE>) [ "+" | "-" { tmp = "-"; }] token=<S_DOUBLE> { retval = new DoubleValue(tmp+token.image); }
1608+
| LOOKAHEAD(["+" | "-"] <S_DOUBLE>) [sign="+" | sign="-"] token=<S_DOUBLE> { retval = new DoubleValue(token.image); }
16091609

1610-
| LOOKAHEAD([ "+" | "-"] <S_LONG>) [ "+" | "-" { tmp = "-"; }] token=<S_LONG> { retval = new LongValue(tmp+token.image); }
1610+
| LOOKAHEAD(["+" | "-"] <S_LONG>) [sign="+" | sign="-"] token=<S_LONG> { retval = new LongValue(token.image); }
16111611

1612-
| LOOKAHEAD(CastExpression()) [ "+" | "-" { isInverse = true; }] retval=CastExpression()
1612+
| LOOKAHEAD(["+" | "-"] CastExpression()) [sign="+" | sign="-"] retval=CastExpression()
16131613

1614-
| LOOKAHEAD(Column()) [ "+" | "-" { isInverse = true; }] retval=Column()
1614+
| LOOKAHEAD(["+" | "-"] Column()) [sign="+" | sign="-"] retval=Column()
16151615

1616-
| LOOKAHEAD(2) [ "+" | "-" { isInverse = true; }] "(" retval=PrimaryExpression() ")" {retval = new Parenthesis(retval); }
1616+
| LOOKAHEAD(2) [sign="+" | sign="-"] "(" retval=PrimaryExpression() ")" {retval = new Parenthesis(retval); }
1617+
1618+
| [sign="+" | sign="-"] "(" retval=SubSelect() ")"
16171619

16181620
| token=<S_CHAR_LITERAL> { retval = new StringValue(token.image); }
16191621

1620-
| [ "+" | "-" { isInverse = true; }] "(" retval=SubSelect() ")"
16211622

1622-
| "{d" token=<S_CHAR_LITERAL> "}" { retval = new DateValue(token.image); }
1623+
| "{d" token=<S_CHAR_LITERAL> "}" { retval = new DateValue(token.image); }
16231624

1624-
| "{t" token=<S_CHAR_LITERAL> "}" { retval = new TimeValue(token.image); }
1625+
| "{t" token=<S_CHAR_LITERAL> "}" { retval = new TimeValue(token.image); }
16251626

1626-
| "{ts" token=<S_CHAR_LITERAL> "}" { retval = new TimestampValue(token.image); }
1627+
| "{ts" token=<S_CHAR_LITERAL> "}" { retval = new TimestampValue(token.image); }
16271628

16281629
| retval = IntervalExpression()
16291630
)
@@ -1637,8 +1638,8 @@ Expression PrimaryExpression():
16371638
} ]
16381639

16391640
{
1640-
if (isInverse) {
1641-
retval = new InverseExpression(retval);
1641+
if (sign != null) {
1642+
retval = new SignedExpression(sign.image.charAt(0), retval);
16421643
}
16431644
return retval;
16441645
}

0 commit comments

Comments
 (0)