Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1176,10 +1176,13 @@ private void visitBinaryLeft(SQLExpr left, SQLBinaryOperator op) {
if (leftRational) {
this.indentCount++;
}
//print('(');
if (!((SQLBinaryOpExpr) left).isParenthesized()) {
print('(');
}
printExpr(left, parameterized);
// print(')');

if (!((SQLBinaryOpExpr) left).isParenthesized()) {
print(')');
}
if (leftRational) {
this.indentCount--;
}
Expand Down
31 changes: 31 additions & 0 deletions core/src/test/java/com/alibaba/druid/sql/issues/Issue6408.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.alibaba.druid.sql.issues;

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
import junit.framework.TestCase;
/**
* @auther nojavacc
* @see <a href="https://github.com/alibaba/druid/issues/6408">...</a >
*/
public class Issue6408 extends TestCase {
public void testSQLBuild() {

// 加法表达式 5+3
SQLBinaryOpExpr addExpr = new SQLBinaryOpExpr();
addExpr.setLeft(new SQLIntegerExpr(5));
addExpr.setOperator(SQLBinaryOperator.Add);
addExpr.setRight(new SQLIntegerExpr(3));

//除法表达式 (5 + 3) / 2
SQLBinaryOpExpr deviceExpr = new SQLBinaryOpExpr();
deviceExpr.setLeft(addExpr);
deviceExpr.setOperator(SQLBinaryOperator.Divide);
deviceExpr.setRight(new SQLIntegerExpr(2));

// 期望输出(5 + 3) / 2,实际输出为 5 + 3 / 2
System.out.println(deviceExpr);


}
}