Skip to content

Commit

Permalink
SQLite Query: Fix more DateOnly/TimeOnly cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Aug 29, 2022
1 parent 1117c14 commit 33a2be7
Show file tree
Hide file tree
Showing 5 changed files with 22 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,17 @@ 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 +55,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 +133,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 33a2be7

Please sign in to comment.