| Author |
Topic |
|
ajthepoolman
Constraint Violating Yak Guru
384 Posts |
Posted - 2003-06-26 : 17:08:58
|
| Hi all. I have one for you that is a brain teaser to me, probably a simple solution to you.Here is my question, how do I set Read/Write permissions at a top node level and have it be recursive through the tree structure?I hope you can follow along:+--Structural Node (#1)+----Databound Node (#2)+--Child Structural Node (#3, child to #1)+----Databound Node (#4, child to #3)+------Child Structural Node (#5, child to #4)+--------Databound Node (#6, child to #5)You are probably thinking, "Go find a Visual Basic forum for this crap.", but you see, the VB code is not my problem right now. I need some SQL help on this one. I have a stored procedure that returns a permission level based on the NodeID that the user selects.So in a nutshell, an Admin sets ReadOnly permissions for Node #1. If a user clicks on node # 4, I need to be able to traverse my tree, getting the top NodeID and checking to see whether the user has Read/Write permissions. So if Node # 1 is set for ReadOnly, I need every node under Node # 1 to be ReadOnly. So Nodes 1 - 6 will return a ReadOnly flag back to the Visual Basic code.I hope this makes sense. Thanks for at least reading this far down!Aj |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2003-06-26 : 17:32:16
|
| An easy way to do this is model your tree of nodes as a left-right tree. Search this site for examples. Then, add a column to the tree table to store your permissions, potentially as a bit-mapped value. Run a query that sums all values for all nodes above the one of interest and you have it.Jonathan{0} |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-06-27 : 08:00:21
|
left-right tree? haven't seen that one here yet. is that the same as joe celko's nested set tree model?searching the forum for "left-right tree" returns only this thread ... - Jeff |
 |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2003-06-27 : 09:48:30
|
| It has many names, but yes the "nested set" is the same idea.Jonathan{0} |
 |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2003-06-27 : 10:25:03
|
Do you work for the same company as Page47?I thought {0} meant something completely different... It has a strong resemblance to a female private part that's all.   |
 |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2003-06-27 : 10:28:19
|
Page47 and I are the principals of the company. The {0} is a mathematical representation of the empty set, a play on "set based" systems. It is entirely aboveboard .Jonathan{0} |
 |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2003-06-27 : 10:33:00
|
quote: The {0} is a mathematical representation of the empty set
Er, no it isn't. It's a set containing one element: zero.Empty set is {} or ∅ (U+2205) |
 |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2003-06-27 : 10:38:07
|
quote: Er, no it isn't. It's a set containing one element: zero.Empty set is {} or ∅ (U+2205)
I think that's what he meant Arnie. Easy on the guy!I prefer my theory though!Long live the {0}   |
 |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2003-06-27 : 10:41:07
|
| Bear in mind that symbol is for marketing only. We don't debate math with our customers, we discuss business solutions.Now, as this thread isn't about my firm, does anyone else have suggestions for AJ?Jonathan{0} |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2003-06-27 : 10:51:49
|
quote: Empty set is {}...
We had to fudge the meaning of things a bit since <0> meant nothing, but had to be used.AJ, you should be able to accomplish this with any hierarchy model in SQL. How are you currently modeling the data?Jay White{0}Edited by - Page47 on 06/27/2003 10:53:51 |
 |
|
|
ajthepoolman
Constraint Violating Yak Guru
384 Posts |
Posted - 2003-06-30 : 14:57:25
|
There is a table called tblUDNode which contains a self-referencing foreign key.Columns:intUDNodeID --Primary KeyintUDNodeParentID --foreign key back to intUDNodeIDSo you could have records: intNodeID | intUDNodeParentID1 | NULL2 | 13 | 14 | 3And so on and so forth.Here is what I did to get around my problem. Since the topic got a little off course I will refresh your memories! I need to have functionality so I can set permissions on a top level node and have it be recursive through the tree structure.So, if I want to set permissions to node 1 to ReadOnly, I need to make sure that any child nodes are also set as such. So, node 4 (since it's parent is 3 whose parent is 1) would also need to be readonly.Here is the code I used:SET NOCOUNT ON --Get the Form ID so we can find out what the upper most node ID is DECLARE @intFormID int SET @intFormID = (select intUDFormID from tblUDNode where intUDNodeID = @intUDNodeID and intUDNodeObsolete = 0) --Now determine what Node ID is the upper most root node for the passed in Node ID DECLARE @intTopLevelParentID int SET @intTopLevelParentID = (select intUDNodeID from tblUDNode where intUDFormID = @intFormID and intUDNodeParentID IS NULL --Null parent ID is the Upper most Node and intUDNodeObsolete = 0) --Find out what the users profile is DECLARE @intProfileID int SET @intProfileID = (select intUserProfileID from tblSysUsers where intSysUserID = @intUserId) --Now build a temp table that holds all the parent node ids for the passed in node DECLARE @tmpNodes TABLE ( intUDNodeID int ) --Insert the current node into the table --This will handle hybrid nodes (nodes with a form but no databound child nodes) INSERT INTO @tmpNodes VALUES ( @intUDNodeID ) DECLARE @intFlag INT SET @intFlag = 1 DECLARE @intCurrentNodeID INT --Now go get all the parent nodes and insert them --The loop will stop when it hits the @intTopLevelParentID node WHILE @intFlag = 1 BEGIN SET @intCurrentNodeID = (SELECT intUDNodeParentID FROM tblUDNode WHERE intUDNodeID = @intUDNodeID AND intUDNodeParentID <> @intTopLevelParentID) IF @intCurrentNodeID IS NOT NULL BEGIN INSERT INTO @tmpNodes VALUES ( @intCurrentNodeID ) SET @intUDNodeID = @intCurrentNodeID END ELSE BEGIN SET @intFlag = 0 END END SET NOCOUNT OFF --Okay, we have the Profile, now check to see what the permission level is for --the passed in node SELECT intCPPermissionDefaultID FROM tblUserProfile_Nodes WHERE intUserProfileID = @intProfileID AND intUDNodeID IN (select * from @tmpNodes) Basically, it gathers a couple of important IDs for use as constraints in my select statements.Then a while loop traverses the tree. So if NodeID # 4 is passed in, it can search up the tree and insert each node id it comes across until it reaches the root node. Then my last chunk of code just does a WHERE IN to see if it was inserted into the temporary table of readonly nodes.It all makes sense to me!Thanks all! Ajbtw, I did use that article as a foundation for this query, so thanks again for the suggestion! |
 |
|
|
|