Skip to content

Commit 609ff0e

Browse files
committed
Ensure nullable RangeRight column uses ISNULL() fallback
Per `SR0007` warnings, nullable columns can bubble up in the results, yielding nullable predicates. In practice, `RangeRight` is only nullable for import scenarios, and is expected to have a value. That said, to be certain, we're using `ISNULL(RangeRight, -1)` anytime it's being referenced. `-1` is used since the `RangeLeft` to `RangeRight` should always be positive; this helps avoid scenario where a `null` triggers a false positive. Again, though, this _shouldn't_ happen in a real-world scenario.
1 parent cd2497d commit 609ff0e

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ BEGIN
220220
WHERE RangeLeft
221221
BETWEEN @InsertionPoint
222222
AND @OriginalRight
223-
OR RangeRight
223+
OR ISNULL(RangeRight, -1)
224224
BETWEEN @InsertionPoint
225225
AND @OriginalRight
226226

@@ -290,7 +290,7 @@ BEGIN
290290
WHERE RangeLeft
291291
BETWEEN @OriginalLeft
292292
AND @InsertionPoint - 1
293-
OR RangeRight
293+
OR ISNULL(RangeRight, 0)
294294
BETWEEN @OriginalLeft
295295
AND @InsertionPoint - 1
296296

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ WHERE (
2626
SELECT COUNT(TopicID)
2727
FROM Topics InnerTopics
2828
WHERE ( RangeLeft < OuterTopics.RangeLeft
29-
AND RangeRight < OuterTopics.RangeRight
30-
AND RangeRight > OuterTopics.RangeLeft
29+
AND ISNULL(RangeRight, -1) < ISNULL(OuterTopics.RangeRight, -1)
30+
AND ISNULL(RangeRight, -1) > OuterTopics.RangeLeft
3131
)
3232
OR ( RangeLeft > OuterTopics.RangeLeft
33-
AND RangeRight > OuterTopics.RangeRight
34-
AND RangeLeft < OuterTopics.RangeRight
33+
AND ISNULL(RangeRight, -1) > ISNULL(OuterTopics.RangeRight, -1)
34+
AND RangeLeft < ISNULL(OuterTopics.RangeRight, -1)
3535
)
3636
) > 0
3737

@@ -54,11 +54,11 @@ WHERE (
5454
WHERE TopicID != OuterTopics.TopicID
5555
AND ( RangeLeft
5656
IN ( OuterTopics.RangeLeft,
57-
OuterTopics.RangeRight
57+
ISNULL(OuterTopics.RangeRight, -1)
5858
)
59-
OR RangeRight
59+
OR ISNULL(RangeRight, 0)
6060
IN ( OuterTopics.RangeLeft,
61-
OuterTopics.RangeRight
61+
ISNULL(OuterTopics.RangeRight, -1)
6262
)
6363
)
6464
) > 0
@@ -74,7 +74,7 @@ SELECT TopicID,
7474
RangeLeft,
7575
RangeRight
7676
FROM Topics
77-
WHERE RangeLeft >= RangeRight
77+
WHERE RangeLeft >= ISNULL(RangeRight, -1)
7878

7979
--------------------------------------------------------------------------------------------------------------------------------
8080
-- DETECT PARENT ID MISMATCHES

0 commit comments

Comments
 (0)