|
1 | | -// Copyright (C) 2018 Xtensive LLC. |
2 | | -// All rights reserved. |
3 | | -// For conditions of distribution and use, see license. |
| 1 | +// Copyright (C) 2018-2021 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 | 4 | // Created by: Alexey Kulakov |
5 | 5 | // Created: 2018.09.21 |
6 | 6 |
|
| 7 | +using Xtensive.Sql.Dml; |
| 8 | + |
7 | 9 | namespace Xtensive.Sql.Drivers.SqlServer.v13 |
8 | 10 | { |
9 | 11 | internal class Compiler : v12.Compiler |
10 | 12 | { |
| 13 | + protected const string DayPart = "DAY"; |
| 14 | + protected const string MillisecondPart = "MS"; |
| 15 | + protected const string NanosecondPart = "NS"; |
| 16 | + protected const string ZeroTime = "'00:00:00.0000000'"; |
| 17 | + |
| 18 | + /// <inheritdoc/> |
| 19 | + public override void Visit(SqlFunctionCall node) |
| 20 | + { |
| 21 | + if (node.FunctionType == SqlFunctionType.DateTimeOffsetTimeOfDay) { |
| 22 | + DateTimeOffsetTimeOfDay(node.Arguments[0]).AcceptVisitor(this); |
| 23 | + } |
| 24 | + else { |
| 25 | + base.Visit(node); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + protected override SqlExpression DateTimeSubtractDateTime(SqlExpression date1, SqlExpression date2) |
| 30 | + { |
| 31 | + return DateDiffBigNanosecond(date2, date1); |
| 32 | + } |
| 33 | + |
| 34 | + #region Static Helpers |
| 35 | + |
| 36 | + protected static SqlUserFunctionCall DateDiffBigNanosecond(SqlExpression date1, SqlExpression date2) => |
| 37 | + SqlDml.FunctionCall("DATEDIFF_BIG", SqlDml.Native(NanosecondPart), date1, date2); |
| 38 | + |
| 39 | + private static SqlExpression DateTimeOffsetTimeOfDay(SqlExpression dateTimeOffset) => |
| 40 | + DateDiffBigNanosecond( |
| 41 | + SqlDml.Native(ZeroTime), |
| 42 | + SqlDml.Cast(dateTimeOffset, new SqlValueType("time"))); |
| 43 | + |
| 44 | + #endregion |
| 45 | + |
11 | 46 | public Compiler(SqlDriver driver) |
12 | 47 | : base(driver) |
13 | 48 | { |
|
0 commit comments