Skip to content

Commit 325ccb0

Browse files
committed
fixes #999
1 parent 7ec06b4 commit 325ccb0

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

nb-configuration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
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>
16+
<netbeans.compile.on.save>all</netbeans.compile.on.save>
1717
<com-junichi11-netbeans-changelf.enable>false</com-junichi11-netbeans-changelf.enable>
1818
<com-junichi11-netbeans-changelf.use-project>true</com-junichi11-netbeans-changelf.use-project>
1919
<com-junichi11-netbeans-changelf.lf-kind>LF</com-junichi11-netbeans-changelf.lf-kind>

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<target>1.8</target>
9292
<showWarnings>true</showWarnings>
9393
<encoding>${project.build.sourceEncoding}</encoding>
94+
<showDeprecation>true</showDeprecation>
9495
</configuration>
9596
</plugin>
9697
<plugin>

src/main/java/net/sf/jsqlparser/expression/operators/conditional/AndExpression.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@
1414
import net.sf.jsqlparser.expression.ExpressionVisitor;
1515

1616
public class AndExpression extends BinaryExpression {
17-
17+
private boolean useOperator = false;
18+
1819
public AndExpression(Expression leftExpression, Expression rightExpression) {
1920
setLeftExpression(leftExpression);
2021
setRightExpression(rightExpression);
2122
}
23+
24+
public void setUseOperator(boolean useOperator) {
25+
this.useOperator = useOperator;
26+
}
27+
28+
public boolean isUseOperator() {
29+
return useOperator;
30+
}
2231

2332
@Override
2433
public void accept(ExpressionVisitor expressionVisitor) {
@@ -27,6 +36,6 @@ public void accept(ExpressionVisitor expressionVisitor) {
2736

2837
@Override
2938
public String getStringExpression() {
30-
return "AND";
39+
return useOperator?"&&":"AND";
3140
}
3241
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void visit(Addition addition) {
9898

9999
@Override
100100
public void visit(AndExpression andExpression) {
101-
visitBinaryExpression(andExpression, " AND ");
101+
visitBinaryExpression(andExpression, andExpression.isUseOperator()?" && ":" AND ");
102102
}
103103

104104
@Override

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,8 @@ Expression AndExpression() :
24152415
{ result = left; }
24162416

24172417
(
2418-
(<K_AND> | <K_AND_OPERATOR>)
2418+
{ boolean useOperator = false; }
2419+
(<K_AND> | <K_AND_OPERATOR> {useOperator=true;} )
24192420
(
24202421
LOOKAHEAD(Condition())
24212422
right=Condition()
@@ -2425,6 +2426,7 @@ Expression AndExpression() :
24252426
)
24262427
{
24272428
result = new AndExpression(left, right);
2429+
((AndExpression)result).setUseOperator(useOperator);
24282430
left = result;
24292431
}
24302432
)*

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3434,7 +3434,7 @@ public void testNestedCast() throws JSQLParserException {
34343434
public void testAndOperator() throws JSQLParserException {
34353435
String stmt = "SELECT name from customers where name = 'John' && lastname = 'Doh'";
34363436
Statement parsed = parserManager.parse(new StringReader(stmt));
3437-
assertStatementCanBeDeparsedAs(parsed, "SELECT name FROM customers WHERE name = 'John' AND lastname = 'Doh'");
3437+
assertStatementCanBeDeparsedAs(parsed, "SELECT name FROM customers WHERE name = 'John' && lastname = 'Doh'");
34383438
}
34393439

34403440
@Test
@@ -4119,4 +4119,9 @@ public void testCurrentIssue940() throws JSQLParserException {
41194119
public void testKeyWordView() throws JSQLParserException {
41204120
assertSqlCanBeParsedAndDeparsed("SELECT ma.m_a_id, ma.anounsment, ma.max_view, ma.end_date, ma.view FROM member_anounsment as ma WHERE ( ( (ma.end_date > now() ) AND (ma.max_view >= ma.view) ) AND ( (ma.member_id='xxx') ) )", true);
41214121
}
4122+
4123+
@Test
4124+
public void testPreserveAndOperator() throws JSQLParserException {
4125+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE 1 = 2 && 2 = 3");
4126+
}
41224127
}

0 commit comments

Comments
 (0)