|
| 1 | +// Copyright (C) 2022 Xtensive LLC. |
| 2 | +// This code is distributed under MIT license terms. |
| 3 | +// See the License.txt file in the project root for more information. |
| 4 | +// Created by: Alexey Kulakov |
| 5 | +// Created: 2022.02.03 |
| 6 | + |
| 7 | +using Xtensive.Sql.Compiler; |
| 8 | +using Xtensive.Sql.Dml; |
| 9 | + |
| 10 | +namespace Xtensive.Sql.Drivers.MySql.v5_7 |
| 11 | +{ |
| 12 | + internal class Compiler : v5_6.Compiler |
| 13 | + { |
| 14 | + /// <inheritdoc/> |
| 15 | + public override void Visit(SqlQueryExpression node) |
| 16 | + { |
| 17 | + using (context.EnterScope(node)) { |
| 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); |
| 22 | + |
| 23 | + context.Output.AppendText(translator.Translate(context, node, QueryExpressionSection.Entry)); |
| 24 | + if (wrapLeft) { |
| 25 | + context.Output.AppendText("("); |
| 26 | + node.Left.AcceptVisitor(this); |
| 27 | + context.Output.AppendText(")"); |
| 28 | + } |
| 29 | + else { |
| 30 | + node.Left.AcceptVisitor(this); |
| 31 | + } |
| 32 | + |
| 33 | + context.Output.AppendText(translator.Translate(node.NodeType)); |
| 34 | + context.Output.AppendText(translator.Translate(context, node, QueryExpressionSection.All)); |
| 35 | + |
| 36 | + if (wrapLeft) { |
| 37 | + context.Output.AppendText("("); |
| 38 | + node.Right.AcceptVisitor(this); |
| 39 | + context.Output.AppendText(")"); |
| 40 | + } |
| 41 | + else { |
| 42 | + node.Right.AcceptVisitor(this); |
| 43 | + } |
| 44 | + |
| 45 | + context.Output.AppendText(translator.Translate(context, node, QueryExpressionSection.Exit)); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + // Constructors |
| 50 | + |
| 51 | + public Compiler(SqlDriver driver) |
| 52 | + : base(driver) |
| 53 | + { |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments