Skip to content

Commit 9e027c4

Browse files
committed
Move IsTimeSpanTicks to SqlHelper
1 parent 6975de4 commit 9e027c4

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v8_0/Compiler.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -548,23 +548,6 @@ private bool TryDivideOffsetIntoParts(SqlExpression offsetInMinutes, ref int hou
548548
return false;
549549
}
550550

551-
private bool IsTimeSpanTicks(SqlExpression expressionToCheck, out SqlExpression source)
552-
{
553-
source = null;
554-
555-
if (expressionToCheck is SqlCast sqlCast && sqlCast.Type.Type==SqlType.Int64) {
556-
var operand = sqlCast.Operand;
557-
if (operand is SqlBinary sqlBinary && sqlBinary.NodeType == SqlNodeType.Divide) {
558-
var left = sqlBinary.Left;
559-
if (left is SqlFunctionCall functionCall && functionCall.FunctionType == SqlFunctionType.IntervalToNanoseconds) {
560-
source = functionCall.Arguments[0];
561-
return true;
562-
}
563-
}
564-
}
565-
return false;
566-
}
567-
568551
// Constructors
569552

570553
protected internal Compiler(SqlDriver driver)

Orm/Xtensive.Orm/Sql/SqlHelper.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,31 @@ public static SqlExpression IntervalToNanoseconds(SqlExpression interval)
171171
return IntervalToMilliseconds(interval) * 1000000L + nanoseconds;
172172
}
173173

174+
/// <summary>
175+
/// Checks if <paramref name="expressionToCheck"/> is indeed a representation of TimeSpan.Ticks
176+
/// created by <see cref="Xtensive.Orm.Providers.TimeSpanCompilers.TimeSpanTicks"/>
177+
/// </summary>
178+
/// <param name="expressionToCheck">Expression to check</param>
179+
/// <param name="sourceInterval">Source interval expression</param>
180+
/// <returns></returns>
181+
public static bool IsTimeSpanTicks(SqlExpression expressionToCheck, out SqlExpression sourceInterval)
182+
{
183+
sourceInterval = null;
184+
185+
if (expressionToCheck is SqlCast sqlCast
186+
&& (sqlCast.Type.Type == SqlType.Int64 || sqlCast.Type.Type == SqlType.Decimal)) {
187+
var operand = sqlCast.Operand;
188+
if (operand is SqlBinary sqlBinary && sqlBinary.NodeType == SqlNodeType.Divide) {
189+
var left = sqlBinary.Left;
190+
if (left is SqlFunctionCall functionCall && functionCall.FunctionType == SqlFunctionType.IntervalToNanoseconds) {
191+
sourceInterval = functionCall.Arguments[0];
192+
return true;
193+
}
194+
}
195+
}
196+
return false;
197+
}
198+
174199
/// <summary>
175200
/// Converts the specified interval expression to expression
176201
/// that represents absolute value (duration) of the specified interval.

0 commit comments

Comments
 (0)