Skip to content

Commit

Permalink
SQLite Query: Fix more DateOnly/TimeOnly cases
Browse files Browse the repository at this point in the history
Fixes #28051
  • Loading branch information
bricelam committed Aug 30, 2022
1 parent 45d0a4a commit 0131b32
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SqliteObjectToStringTranslator : IMethodCallTranslator
typeof(byte),
typeof(byte[]),
typeof(char),
typeof(DateOnly),
typeof(DateTime),
typeof(DateTimeOffset),
typeof(decimal),
Expand All @@ -29,6 +30,7 @@ public class SqliteObjectToStringTranslator : IMethodCallTranslator
typeof(long),
typeof(sbyte),
typeof(short),
typeof(TimeOnly),
typeof(TimeSpan),
typeof(uint),
typeof(ushort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ private static readonly IReadOnlyDictionary<ExpressionType, IReadOnlyCollection<
{
[ExpressionType.Add] = new HashSet<Type>
{
typeof(DateOnly),
typeof(DateTime),
typeof(DateTimeOffset),
typeof(TimeOnly),
typeof(TimeSpan)
},
[ExpressionType.Divide] = new HashSet<Type> { typeof(TimeSpan), typeof(ulong) },
[ExpressionType.Divide] = new HashSet<Type>
{
typeof(TimeOnly),
typeof(TimeSpan),
typeof(ulong)
},
[ExpressionType.GreaterThan] = new HashSet<Type>
{
typeof(DateTimeOffset),
Expand All @@ -49,11 +56,18 @@ private static readonly IReadOnlyDictionary<ExpressionType, IReadOnlyCollection<
typeof(ulong)
},
[ExpressionType.Modulo] = new HashSet<Type> { typeof(ulong) },
[ExpressionType.Multiply] = new HashSet<Type> { typeof(TimeSpan), typeof(ulong) },
[ExpressionType.Multiply] = new HashSet<Type>
{
typeof(TimeOnly),
typeof(TimeSpan),
typeof(ulong)
},
[ExpressionType.Subtract] = new HashSet<Type>
{
typeof(DateOnly),
typeof(DateTime),
typeof(DateTimeOffset),
typeof(TimeOnly),
typeof(TimeSpan)
}
};
Expand Down Expand Up @@ -120,7 +134,8 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression)
visitedExpression.Type);
}

if (operandType == typeof(TimeSpan))
if (operandType == typeof(TimeOnly)
|| operandType == typeof(TimeSpan))
{
return QueryCompilationContext.NotTranslatedExpression;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public override async Task Where_TimeOnly_IsBetween(bool async)
public override async Task Where_TimeOnly_subtract_TimeOnly(bool async)
{
// TimeSpan. Issue #18844.
await Assert.ThrowsAsync<InvalidCastException>(() => base.Where_TimeOnly_subtract_TimeOnly(async));
await AssertTranslationFailed(() => base.Where_TimeOnly_subtract_TimeOnly(async));

AssertSql();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public override Task Where_TimeOnly_IsBetween(bool async)

public override Task Where_TimeOnly_subtract_TimeOnly(bool async)
// TimeSpan. Issue #18844.
=> Assert.ThrowsAsync<InvalidCastException>(() => base.Where_TimeOnly_subtract_TimeOnly(async));
=> AssertTranslationFailed(() => base.Where_TimeOnly_subtract_TimeOnly(async));

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public override Task Where_TimeOnly_IsBetween(bool async)

public override Task Where_TimeOnly_subtract_TimeOnly(bool async)
// TimeSpan. Issue #18844.
=> Assert.ThrowsAsync<InvalidCastException>(() => base.Where_TimeOnly_subtract_TimeOnly(async));
=> AssertTranslationFailed(() => base.Where_TimeOnly_subtract_TimeOnly(async));

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
Expand Down

0 comments on commit 0131b32

Please sign in to comment.