Skip to content

Commit

Permalink
Fix to #29260 - Sqlite: AddTicks translation gives incorrect results (#…
Browse files Browse the repository at this point in the history
…29274)

We were using TimeSpan.TicksPerDay rather than TicksPerSecond in the translation. Fixing the typo and correcting the test.

Fixes #29260
  • Loading branch information
maumar authored Oct 6, 2022
1 parent 2c75ef1 commit 42df85e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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""
FROM ""Orders"" AS ""o""
WHERE ""o"".""OrderDate"" IS NOT NULL");
}
Expand Down

0 comments on commit 42df85e

Please sign in to comment.