Skip to content

Commit 5d0ea80

Browse files
committed
Merge branch 'improvement/SQL-DATETIME2' into develop
Previously, the SQL database objects—including tables, stored procedures, and functions—used `DATETIME` for e.g. `Version` parameters and columns. The `DATETIME` has severe limitations, however, and is only intended for backward compatibility. Instead, it is preferred for databases to use the new(er) `DATETIME2` data type, which supports not only a wider date range, but also higher precision. As part of this, we were able to establish full compatibility with the .NET CLR's `Int32` (`int`) type, whereas previously we needed to truncate its values using `SqlDateTime`. We may not need the full `DATETIME2(7)` precision established here; certainly, it's rare that a topic is updated twice in as many ticks—though certainly not unheard of, and especially during automated updates or tests. We may opt to reevaluate this precision later.
2 parents fa68cb1 + 835fca0 commit 5d0ea80

19 files changed

Lines changed: 39 additions & 37 deletions

OnTopic.Data.Sql.Database/Functions/GetAttributes.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RETURNS @Attributes TABLE
1313
AttributeKey NVARCHAR(255) NOT NULL,
1414
AttributeValue NVARCHAR(MAX) NOT NULL,
1515
IsExtendedAttribute BIT,
16-
Version DATETIME
16+
Version DATETIME2(7)
1717
)
1818
AS
1919

OnTopic.Data.Sql.Database/Functions/GetChildTopicIDs.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ BEGIN
2222
------------------------------------------------------------------------------------------------------------------------------
2323
IF (@TopicID IS NULL)
2424
BEGIN
25-
SET @TopicID = ''
25+
SET @TopicID = -10
2626
END
2727

2828
------------------------------------------------------------------------------------------------------------------------------
@@ -32,7 +32,7 @@ BEGIN
3232
INTO @Topics
3333
SELECT TopicID
3434
FROM Topics
35-
WHERE ISNULL(ParentID, '') = @TopicID
35+
WHERE ISNULL(ParentID, -10) = @TopicID
3636

3737
------------------------------------------------------------------------------------------------------------------------------
3838
-- RETURN

OnTopic.Data.Sql.Database/Scripts/Upgrade from OnTopic 3 to OnTopic 4.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ INTO topics_TopicAttributes
3232
SELECT SourceTopicID,
3333
'Type',
3434
AttributeTypes.AttributeValue,
35-
GETDATE()
35+
SYSUTCDATETIME()
3636
FROM (
3737
SELECT TopicID AS SourceTopicID,
3838
AttributeKey,

OnTopic.Data.Sql.Database/Stored Procedures/CreateTopic.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ CREATE PROCEDURE [dbo].[CreateTopic]
1111
@Attributes AttributeValues READONLY,
1212
@ExtendedAttributes XML = NULL,
1313
@References TopicReferences READONLY,
14-
@Version DATETIME = NULL
14+
@Version DATETIME2(7) = NULL
1515
AS
1616

1717
--------------------------------------------------------------------------------------------------------------------------------
1818
-- SET DEFAULT VERSION DATETIME
1919
--------------------------------------------------------------------------------------------------------------------------------
2020
IF @Version IS NULL
21-
SET @Version = GETUTCDATE()
21+
SET @Version = SYSUTCDATETIME()
2222

2323
--------------------------------------------------------------------------------------------------------------------------------
2424
-- DECLARE AND SET VARIABLES
@@ -119,6 +119,7 @@ IF @ReferenceCount > 0
119119
BEGIN
120120
EXEC UpdateReferences @TopicID,
121121
@References,
122+
@Version,
122123
1
123124
END
124125

OnTopic.Data.Sql.Database/Stored Procedures/GetTopicUpdates.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
--------------------------------------------------------------------------------------------------------------------------------
66

77
CREATE PROCEDURE [dbo].[GetTopicUpdates]
8-
@Since DATETIME
8+
@Since DATETIME2(7)
99
AS
1010

1111
--------------------------------------------------------------------------------------------------------------------------------

OnTopic.Data.Sql.Database/Stored Procedures/GetTopicVersion.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
CREATE PROCEDURE [dbo].[GetTopicVersion]
88
@TopicID INT = -1,
9-
@Version DATETIME = NULL
9+
@Version DATETIME2(7) = NULL
1010
AS
1111

1212
--------------------------------------------------------------------------------------------------------------------------------

OnTopic.Data.Sql.Database/Stored Procedures/UpdateAttributes.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
CREATE PROCEDURE [dbo].[UpdateAttributes]
99
@TopicID INT,
1010
@Attributes AttributeValues READONLY ,
11-
@Version DATETIME = NULL ,
11+
@Version DATETIME2(7) = NULL ,
1212
@DeleteUnmatched BIT = 0
1313
AS
1414

OnTopic.Data.Sql.Database/Stored Procedures/UpdateExtendedAttributes.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
CREATE PROCEDURE [dbo].[UpdateExtendedAttributes]
88
@TopicID INT,
99
@ExtendedAttributes XML = NULL ,
10-
@Version DATETIME = NULL ,
10+
@Version DATETIME2(7) = NULL ,
1111
@DeleteUnmatched BIT = 0
1212
AS
1313

OnTopic.Data.Sql.Database/Stored Procedures/UpdateReferences.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
CREATE PROCEDURE [dbo].[UpdateReferences]
88
@TopicID INT,
99
@ReferencedTopics TopicReferences READONLY ,
10-
@Version DATETIME = NULL ,
10+
@Version DATETIME2(7) = NULL ,
1111
@DeleteUnmatched BIT = 0
1212
AS
1313

1414
--------------------------------------------------------------------------------------------------------------------------------
1515
-- SET DEFAULT VERSION DATETIME
1616
--------------------------------------------------------------------------------------------------------------------------------
1717
IF @Version IS NULL
18-
SET @Version = GETUTCDATE()
18+
SET @Version = SYSUTCDATETIME()
1919

2020
--------------------------------------------------------------------------------------------------------------------------------
2121
-- INSERT NOVEL VALUES

OnTopic.Data.Sql.Database/Stored Procedures/UpdateRelationships.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ CREATE PROCEDURE [dbo].[UpdateRelationships]
88
@TopicID INT,
99
@RelationshipKey VARCHAR(255),
1010
@RelatedTopics TopicList READONLY ,
11-
@Version DATETIME = NULL ,
11+
@Version DATETIME2(7) = NULL ,
1212
@DeleteUnmatched BIT = 0
1313
AS
1414

1515
--------------------------------------------------------------------------------------------------------------------------------
1616
-- SET DEFAULT VERSION DATETIME
1717
--------------------------------------------------------------------------------------------------------------------------------
1818
IF @Version IS NULL
19-
SET @Version = GETUTCDATE()
19+
SET @Version = SYSUTCDATETIME()
2020

2121
--------------------------------------------------------------------------------------------------------------------------------
2222
-- INSERT NOVEL VALUES

0 commit comments

Comments
 (0)