Skip to content

Commit

Permalink
Merge pull request #507 from Particular/dateadd
Browse files Browse the repository at this point in the history
Fix DATEADD overflow by passing timespan parts to SQL layer
  • Loading branch information
danielmarbach authored Oct 16, 2019
2 parents 9808911 + 5e38afd commit fe6c4f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public void PrepareSendCommand(SqlCommand command)
{
AddParameter(command, "Headers", SqlDbType.NVarChar, headers);
AddParameter(command, "Body", SqlDbType.VarBinary, bodyBytes);
AddParameter(command, "DueAfterMs", SqlDbType.BigInt, dueAfter.TotalMilliseconds);
AddParameter(command, "DueAfterDays", SqlDbType.Int, dueAfter.Days);
AddParameter(command, "DueAfterHours", SqlDbType.Int, dueAfter.Hours);
AddParameter(command, "DueAfterMinutes", SqlDbType.Int, dueAfter.Minutes);
AddParameter(command, "DueAfterSeconds", SqlDbType.Int, dueAfter.Seconds);
AddParameter(command, "DueAfterMilliseconds", SqlDbType.Int, dueAfter.Milliseconds);
}

void AddParameter(SqlCommand command, string name, SqlDbType type, object value)
Expand Down
9 changes: 8 additions & 1 deletion src/NServiceBus.SqlServer/Queuing/SqlConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ THEN DATEADD(ms, @TimeToBeReceivedMs, GETUTCDATE()) END,
IF ( (512 & @@OPTIONS) = 512 ) SET @NOCOUNT = 'ON'
SET NOCOUNT ON;
DECLARE @DueAfter DATETIME = GETUTCDATE();
SET @DueAfter = DATEADD(ms, @DueAfterMilliseconds, @DueAfter);
SET @DueAfter = DATEADD(s, @DueAfterSeconds, @DueAfter);
SET @DueAfter = DATEADD(n, @DueAfterMinutes, @DueAfter);
SET @DueAfter = DATEADD(hh, @DueAfterHours, @DueAfter);
SET @DueAfter = DATEADD(d, @DueAfterDays, @DueAfter);
INSERT INTO {0} (
Headers,
Body,
Due)
VALUES (
@Headers,
@Body,
DATEADD(ms, @DueAfterMs, GETUTCDATE()));
@DueAfter);
IF(@NOCOUNT = 'ON') SET NOCOUNT ON;
IF(@NOCOUNT = 'OFF') SET NOCOUNT OFF;";
Expand Down

0 comments on commit fe6c4f2

Please sign in to comment.