Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0] Fix to #29260 - Sqlite: AddTicks translation gives incorrect results #29274

Merged
1 commit merged into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public SqliteDateTimeAddTranslator(SqliteSqlExpressionFactory sqlExpressionFacto
_sqlExpressionFactory.Convert(
_sqlExpressionFactory.Divide(
arguments[0],
_sqlExpressionFactory.Constant((double)TimeSpan.TicksPerDay)),
_sqlExpressionFactory.Constant((double)TimeSpan.TicksPerSecond)),
typeof(string)),
_sqlExpressionFactory.Constant(" seconds"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ public override async Task Select_expression_datetime_add_second(bool async)

public override async Task Select_expression_datetime_add_ticks(bool async)
{
// Add ticks. Issue #25851.
Assert.Equal(
"1996-07-04T00:00:00.0000000",
(await Assert.ThrowsAsync<EqualException>(
() => base.Select_expression_datetime_add_ticks(async))).Actual);
// modifying the original scenario - Sqlite gives inaccurate results for values of granularity less than 1 second
await AssertQuery(
async,
ss => ss.Set<Order>().Where(o => o.OrderDate != null)
.Select(o => new Order { OrderDate = o.OrderDate.Value.AddTicks(10 * TimeSpan.TicksPerSecond) }),
e => e.OrderDate);

AssertSql(
@"SELECT rtrim(rtrim(strftime('%Y-%m-%d %H:%M:%f', ""o"".""OrderDate"", CAST((10000 / 864000000000) AS TEXT) || ' seconds'), '0'), '.') AS ""OrderDate""
@"SELECT rtrim(rtrim(strftime('%Y-%m-%d %H:%M:%f', ""o"".""OrderDate"", CAST((100000000 / 10000000) AS TEXT) || ' seconds'), '0'), '.') AS ""OrderDate""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For extra credit, if it's a constant we can perform the calculation during translation and embed the result.

IIRC with @smitpatel at some point we talked about a post-processing thing that would do this in one place.

FROM ""Orders"" AS ""o""
WHERE ""o"".""OrderDate"" IS NOT NULL");
}
Expand Down