Skip to content

Commit 05ae378

Browse files
committed
Update GetAttributes to return correct data
Technically, the `GetAttributes` stored procedure is a vestigal artifact of the original version of OnTopic from over a decade ago, and is not documented or used in any production code. As such, it could be deleted. Indeed, while it's been kept up to date with schema changes, it hasn't accomodated more recent features such as `ExtendedAttributes` or `Version`, which make it entirely useless. That said, instead of throwing it out, I've updated it to our latest standards as a useful utility function by incorporating both versioning as well as extended attributes. This includes a query to parse the XML of the latest `ExtendedAttributes` record and `UNION` it against the main `Attributes`. While technically this could be stored in the `Utilities` schema, it has potential production use, and so I'm going to keep it under `dbo`. It's reasonably fast, and useful for pulling just the attributes of any given topic. We can reevaluate this in the next version of OnTopic, if appropriate. It's worth noting that this does _not_ include `Key`, `ParentID`, or `ContentType`, as these are excluded from the main `Attributes` collection. We may want to reevaluate that in the future as well.
1 parent 17b98b4 commit 05ae378

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--------------------------------------------------------------------------------------------------------------------------------
22
-- GET TOPIC ATTRIBUTES
33
--------------------------------------------------------------------------------------------------------------------------------
4-
-- Returns a list of attributes associated with a particular topic.
4+
-- Returns the most recent value of each attribute associated with a particular topic.
55
--------------------------------------------------------------------------------------------------------------------------------
66
CREATE PROCEDURE [dbo].[GetAttributes]
77
@TopicID INT = -1
@@ -13,10 +13,33 @@ AS
1313
SET NOCOUNT ON;
1414

1515
--------------------------------------------------------------------------------------------------------------------------------
16-
-- SELECT ATTRIBUTES
16+
-- SELECT MOST RECENT ATTRIBUTES
1717
--------------------------------------------------------------------------------------------------------------------------------
1818
SELECT AttributeKey,
19-
AttributeValue
20-
FROM Attributes
19+
AttributeValue,
20+
0 AS IsExtendedAttribute,
21+
Version
22+
FROM AttributeIndex
23+
WHERE TopicID = @TopicID
24+
25+
UNION
26+
27+
--------------------------------------------------------------------------------------------------------------------------------
28+
-- PARSE MOST RECENT EXTENDED ATTRIBUTES
29+
--------------------------------------------------------------------------------------------------------------------------------
30+
SELECT Attributes.Loc.value(
31+
'@key',
32+
'VARCHAR(255)'
33+
) AS AttributeKey,
34+
Attributes.Loc.value(
35+
'.[1]',
36+
'VARCHAR(MAX)'
37+
) AS AttributeValue,
38+
1 AS IsExtendedAttribute,
39+
Version
40+
FROM ExtendedAttributeIndex
41+
CROSS APPLY AttributesXml.nodes(
42+
'/attributes/attribute'
43+
) AS Attributes(Loc)
2144
WHERE TopicID = @TopicID
2245
ORDER BY AttributeKey

0 commit comments

Comments
 (0)