Skip to content

Commit adcf6a1

Browse files
committed
Introduced new GetVersion() extension
When we introduced the `GetDateTime()` extension method in #dde0ade, we inadvertantly reduced the precision of the `DateTime` value returned. This is a problem since this is used for `Version` (e.g., when setting the `VersionHistory`) and that's a place where the precision must match the database exactly. Unfortunately, the logic for this is a bit different than it is for other types, since it's the interstitial string conversion that's introducing the problem here. To mitigate that, we must duplicate some of the logic from the private `GetValue<T>()` in order to explicitly avoid that conversion, and instead pull the value explicitly using the `GetDateTime()` method. This process won't actually work with other types of `DateTime` values, such as those encoded as a string in the `Attributes` table. As such, to differentiate these, this is being introduced as `GetVersion()`.
1 parent 47ef38d commit adcf6a1

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

OnTopic.Data.Sql/SqlDataReaderExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ internal static string GetString(this SqlDataReader reader, string columnName) =
5858
internal static DateTime GetDateTime(this SqlDataReader reader, string columnName) =>
5959
GetValue<DateTime>(reader, columnName, DateTime.TryParse, DateTime.MinValue);
6060

61+
/*==========================================================================================================================
62+
| METHOD: GET VERSION
63+
\-------------------------------------------------------------------------------------------------------------------------*/
64+
/// <summary>
65+
/// Retrieves the version column, with precisions appropriate for setting the <see cref="Topic.VersionHistory"/>.
66+
/// </summary>
67+
/// <param name="reader">The <see cref="SqlDataReader"/> object.</param>
68+
internal static DateTime GetVersion(this SqlDataReader reader) =>
69+
reader.GetDateTime(reader.GetOrdinal("Version"));
70+
6171
/*==========================================================================================================================
6272
| METHOD: GET BOOLEAN
6373
\-------------------------------------------------------------------------------------------------------------------------*/

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private static void SetIndexedAttributes(SqlDataReader reader, Dictionary<int, T
118118
//Check field count to avoid breaking changes with the 4.0.0 release, which didn't include a "Version" column
119119
//### TODO JJC20200221: This condition can be removed and accepted as a breaking change in v5.0.
120120
if (reader.FieldCount > 3) {
121-
version = reader.GetDateTime("Version");
121+
version = reader.GetVersion();
122122
}
123123

124124
/*------------------------------------------------------------------------------------------------------------------------
@@ -173,7 +173,7 @@ private static void SetExtendedAttributes(SqlDataReader reader, Dictionary<int,
173173
//Check field count to avoid breaking changes with the 4.0.0 release, which didn't include a "Version" column
174174
//### TODO JJC20200221: This condition can be removed and accepted as a breaking change in v5.0.
175175
if (reader.FieldCount > 2) {
176-
version = reader.GetDateTime("Version");
176+
version = reader.GetVersion();
177177
}
178178

179179
/*------------------------------------------------------------------------------------------------------------------------
@@ -331,7 +331,7 @@ private static void SetVersionHistory(SqlDataReader reader, Dictionary<int, Topi
331331
| Identify attributes
332332
\-----------------------------------------------------------------------------------------------------------------------*/
333333
var sourceTopicId = reader.GetInteger("TopicID");
334-
var dateTime = reader.GetDateTime("Version");
334+
var dateTime = reader.GetVersion();
335335

336336
/*------------------------------------------------------------------------------------------------------------------------
337337
| Identify topic

0 commit comments

Comments
 (0)