Skip to content

Commit af695af

Browse files
committed
Mysql: No support for TimeConstruct operation
There is no way to control hours overflow, Even MAKETIME function returns NULL or max value if value is incorrect, this opens way to possibly corrupted query results which is bad
1 parent df202d1 commit af695af

File tree

3 files changed

+0
-101
lines changed

3 files changed

+0
-101
lines changed

Orm/Xtensive.Orm.MySql/Sql.Drivers.MySql/v5_0/Compiler.cs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ internal class Compiler : SqlCompiler
2424
protected const long NanosecondsPerMicrosecond = 1000;
2525
protected const long MillisecondsPerDay = 86400000;
2626

27-
//protected static readonly long NanosecondsPerDay = TimeSpan.FromDays(1).Ticks * 100;
28-
//protected static readonly long NanosecondsPerSecond = 1000000000;
29-
//protected static readonly long NanosecondsPerMillisecond = 1000000;
30-
//protected static readonly long NanosecondsPerMicrosecond = 1000;
31-
//protected static readonly long MillisecondsPerDay = (long) TimeSpan.FromDays(1).TotalMilliseconds;
32-
//protected static readonly long MillisecondsPerSecond = 1000L;
33-
3427
/// <inheritdoc/>
3528
public override void Visit(SqlSelect node)
3629
{
@@ -222,9 +215,6 @@ public override void Visit(SqlFunctionCall node)
222215
SqlDml.RawConcat(SqlDml.Native("INTERVAL "), SqlDml.FunctionCall("TIME_TO_SEC", arguments[0]) + arguments[1] * 60),
223216
SqlDml.Native("SECOND")))));
224217
return;
225-
case SqlFunctionType.TimeConstruct:
226-
ConstructTime(arguments).AcceptVisitor(this);
227-
return;
228218
case SqlFunctionType.TimeToNanoseconds:
229219
TimeToNanoseconds(arguments[0]).AcceptVisitor(this);
230220
return;
@@ -341,38 +331,6 @@ protected virtual SqlExpression ConstructDate(IReadOnlyList<SqlExpression> argum
341331
arguments[2] - 1);
342332
}
343333

344-
protected virtual SqlExpression ConstructTime(IReadOnlyList<SqlExpression> arguments)
345-
{
346-
SqlExpression hour, minute, second, millisecond;
347-
if (arguments.Count == 4) {
348-
hour = arguments[0];
349-
minute = arguments[1];
350-
second = arguments[2];
351-
millisecond = arguments[3];
352-
}
353-
else if (arguments.Count == 1) {
354-
var ticks = arguments[0];
355-
hour = SqlDml.Cast(ticks / 36000000000, SqlType.Int32);
356-
minute = SqlDml.Cast((ticks / 600000000) % 60, SqlType.Int32);
357-
second = SqlDml.Cast((ticks / 10000000) % 60, SqlType.Int32);
358-
millisecond = 0; //SqlDml.Cast((ticks % 10000000) / 10, SqlType.Int32);
359-
}
360-
else {
361-
throw new InvalidOperationException("Unsupported count of parameters");
362-
}
363-
364-
return SqlDml.FunctionCall("TIME",
365-
TimeAddMillisecond(
366-
TimeAddSecond(
367-
TimeAddMinute(
368-
TimeAddHour(
369-
SqlDml.Literal(new DateTime(2001, 1, 1)),
370-
hour),
371-
minute),
372-
second),
373-
millisecond));
374-
}
375-
376334
protected virtual SqlExpression TimeToNanoseconds(SqlExpression time)
377335
{
378336
var nPerHour = SqlDml.Extract(SqlTimePart.Hour, time) * NanosecondsPerHour;

Orm/Xtensive.Orm.MySql/Sql.Drivers.MySql/v5_6/Compiler.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,40 +61,6 @@ protected override SqlBinary TimeSubtractTime(SqlExpression time1, SqlExpression
6161
SqlDml.Modulo(
6262
NanosecondsPerDay + CastToDecimal(DateTimeDiffMicrosecond(time2, time1), 18, 0) * NanosecondsPerMicrosecond,
6363
NanosecondsPerDay);
64-
65-
protected override SqlUserFunctionCall ConstructTime(IReadOnlyList<SqlExpression> arguments)
66-
{
67-
SqlExpression hour, minute, second, millisecond;
68-
if (arguments.Count == 4) {
69-
hour = arguments[0];
70-
minute = arguments[1];
71-
second = arguments[2];
72-
millisecond = arguments[3];
73-
}
74-
else if (arguments.Count == 1) {
75-
var ticks = arguments[0];
76-
if (SqlHelper.IsTimeSpanTicks(ticks, out var sourceInterval)) {
77-
hour = SqlDml.Cast(ticks / 36000000000, SqlType.Int32);
78-
minute = SqlDml.Cast((ticks / 600000000) % 60, SqlType.Int32);
79-
second = SqlDml.Cast((ticks / 10000000) % 60, SqlType.Int32);
80-
millisecond = SqlDml.Cast((ticks % 10000000) / 10, SqlType.Int32) / 1000;
81-
}
82-
else {
83-
hour = SqlDml.Cast(ticks / 36000000000, SqlType.Int32);
84-
minute = SqlDml.Cast((ticks / 600000000) % 60, SqlType.Int32);
85-
second = SqlDml.Cast((ticks / 10000000) % 60, SqlType.Int32);
86-
millisecond = SqlDml.Cast((ticks % 10000000) / 10, SqlType.Int32) / 1000;
87-
}
88-
}
89-
else {
90-
throw new InvalidOperationException("Unsupported count of parameters");
91-
}
92-
return MakeTime(hour, minute, second, millisecond);
93-
}
94-
95-
protected SqlUserFunctionCall MakeTime(
96-
SqlExpression hours, SqlExpression minutes, SqlExpression seconds, SqlExpression milliseconds) =>
97-
SqlDml.FunctionCall("MAKETIME", hours, minutes, seconds + (milliseconds / 1000));
9864
#endif
9965

10066
// Constructors

Orm/Xtensive.Orm.Tests/Linq/DateTimeAndDateTimeOffset/TimeOnly/ConstructorTest.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,6 @@ public void CtorTicksFromIntervalTicks()
107107
});
108108
}
109109

110-
[Test]
111-
public void MysqlCtorTicksFromIntervalTicks()
112-
{
113-
Require.ProviderIs(StorageProvider.MySql);
114-
115-
if (StorageProviderInfo.Instance.Info.StorageVersion <= StorageProviderVersion.MySql55) {
116-
ExecuteInsideSession((s) => {
117-
var result = s.Query.All<AllPossiblePartsEntity>()
118-
.Select(e => new { Entity = e, ConstructedTime = new TimeOnly(e.TimeSpan.Ticks) })
119-
.Where(a => a.ConstructedTime == FirstTimeOnly)
120-
.OrderBy(a => a.Entity.Id).ToList(3);
121-
Assert.That(result.Count, Is.EqualTo(1));
122-
});
123-
}
124-
else {
125-
ExecuteInsideSession((s) => {
126-
var result = s.Query.All<AllPossiblePartsEntity>()
127-
.Select(e => new { Entity = e, ConstructedTime = new TimeOnly(e.TimeSpan.Ticks) })
128-
.Where(a => a.ConstructedTime == FirstMillisecondTimeOnly)
129-
.OrderBy(a => a.Entity.Id).ToList(3);
130-
Assert.That(result.Count, Is.EqualTo(1));
131-
});
132-
}
133-
}
134-
135110
[Test]
136111
public void TicksFromColumnsBasedExpression()
137112
{

0 commit comments

Comments
 (0)