@@ -15,18 +15,32 @@ internal class Compiler : v5_7.Compiler
1515 public override void Visit ( SqlQueryExpression node )
1616 {
1717 using ( context . EnterScope ( node ) ) {
18- bool needOpeningParenthesis = true ;
19- bool needClosingParenthesis = true ;
18+ var wrapLeft = node . Left is SqlSelect sL
19+ && ( sL . OrderBy . Count > 0 || ! sL . HasLimit || sL . Lock != SqlLockType . Empty ) ;
20+ var wrapRight = node . Left is SqlSelect sR
21+ && ( sR . OrderBy . Count > 0 || ! sR . HasLimit || sR . Lock != SqlLockType . Empty ) ;
2022
2123 AppendTranslatedEntry ( node ) ;
22- _ = context . Output . Append ( "(" ) ;
23- node . Left . AcceptVisitor ( this ) ;
24- _ = context . Output . Append ( ")" ) ;
24+ if ( wrapLeft ) {
25+ _ = context . Output . Append ( "(" ) ;
26+ node . Left . AcceptVisitor ( this ) ;
27+ _ = context . Output . Append ( ")" ) ;
28+ }
29+ else {
30+ node . Left . AcceptVisitor ( this ) ;
31+ }
32+
2533 AppendTranslated ( node . NodeType ) ;
2634 AppendTranslated ( node , QueryExpressionSection . All ) ;
27- _ = context . Output . Append ( "(" ) ;
28- node . Right . AcceptVisitor ( this ) ;
29- _ = context . Output . Append ( ")" ) ;
35+
36+ if ( wrapRight ) {
37+ _ = context . Output . Append ( "(" ) ;
38+ node . Right . AcceptVisitor ( this ) ;
39+ _ = context . Output . Append ( ")" ) ;
40+ }
41+ else {
42+ node . Right . AcceptVisitor ( this ) ;
43+ }
3044 AppendTranslatedExit ( node ) ;
3145 }
3246 }
0 commit comments