Skip to content

Commit b59c5c3

Browse files
committed
MySql provider: DateTime related improvements
- extraction of DateTime type - v5.6+ uses datetime(6) everywhere, not only in parameters; this will fix certain comparisons because before that parameters where of datetime(6) type but values were cast to datetime (no ms part)
1 parent 7a1b1a2 commit b59c5c3

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2011-2023 Xtensive LLC.
1+
// Copyright (C) 2011-2025 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Malisa Ncube
@@ -399,6 +399,9 @@ private SqlValueType CreateValueType(IDataRecord row,
399399
// although they can be read as "scale" and "precision"
400400
return new SqlValueType(SqlType.Int64);
401401
}
402+
if (typeName.StartsWith("DATETIME", StringComparison.Ordinal)) {
403+
return new SqlValueType(SqlType.DateTime);
404+
}
402405

403406
if (typeName.StartsWith("TIME")) {
404407
// "timestamp precision" is saved as "scale", ignoring too

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2013-2025 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alena Mikshina
55
// Created: 2013.12.30
66

7+
using System;
8+
using Xtensive.Sql.Info;
9+
710
namespace Xtensive.Sql.Drivers.MySql.v5_6
811
{
912
internal class ServerInfoProvider : v5_5.ServerInfoProvider
1013
{
14+
/// <inheritdoc/>
15+
public override DataTypeCollection GetDataTypesInfo()
16+
{
17+
var types = base.GetDataTypesInfo();
18+
19+
var common = DataTypeFeatures.Default | DataTypeFeatures.Nullable | DataTypeFeatures.NonKeyIndexing |
20+
DataTypeFeatures.Grouping | DataTypeFeatures.Ordering | DataTypeFeatures.Multiple;
21+
22+
var index = DataTypeFeatures.Indexing | DataTypeFeatures.KeyConstraint;
23+
24+
types.DateTime = DataTypeInfo.Range(SqlType.DateTime, common | index,
25+
new ValueRange<DateTime>(new DateTime(1000, 1, 1), new DateTime(9999, 12, 31)),
26+
"datetime(6)", "datetime", "time(6)", "time");
27+
return types;
28+
}
29+
1130
// Constructors
1231

1332
public ServerInfoProvider(SqlDriver driver)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2013-2025 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alena Mikshina
55
// Created: 2013.12.30
66

@@ -20,7 +20,7 @@ public override string Translate(SqlCompilerContext context, SqlCast node, NodeS
2020
case NodeSection.Entry:
2121
return "CAST(";
2222
case NodeSection.Exit:
23-
return "AS " + Translate(node.Type) + "(6))";
23+
return "AS " + Translate(node.Type) + ")";
2424
default:
2525
throw new ArgumentOutOfRangeException("section");
2626
}

0 commit comments

Comments
 (0)