| Author |
Topic  |
|
AskSQLTeam
Ask SQLTeam Question
USA
0 Posts |
|
|
Anonymous
Starting Member
0 Posts |
|
|
graz
Chief SQLTeam Crack Dealer
USA
4128 Posts |
|
|
Anonymous
Starting Member
0 Posts |
|
|
Anonymous
Starting Member
0 Posts |
|
|
Anonymous
Starting Member
0 Posts |
Posted - 11/20/2000 : 16:21:18
|
| Response to BAH Rather than using A-Z, choose a set of 64 characters and use base 64 encoding. More efficient than 26 on two levels: If you are using some external language to generate the IDs, you can do it with bit-shifting instead of integer divide and modulo. And, of course, you need even fewer "digits" to accomplish the same result.
However...
Isn't it true that most DBs aren't going to let you create an index on a text field longer than 255 characters? (And you certainly want this field to be indexed, don't you? For the ORDER BY to be reasonably efficient?) If so, then the limit you run into is the number of "levels" of response allowed. Assume we use 4 base-64 "digits" for a message number. Then the limit becomes 63 response levels, right? Of course, even 3 base-64 digits allows message numbers up to 262143, which should be enough for most any message board, and bumps the number of response levels up to 85.
Ehhh...if you can't get along with a message board that allows up to 85 levels of response and 256K messages, then maybe you need to find yet another scheme?
I'm using this scheme in an ASP-based board, and even using Access (for prototyping! don't jump on me!) it works really well.
(Okay, I admit to using 4 base-64 digits...don't ask me why.)
Incidentally, didn't mean to be anonymous. Bill Wilkinson of ChiliSoft...errr...of Cobalt Networks....err, of Sun, I guess, next month. billw@chilisoft.com for now, at least. |
 |
|
|
Anonymous
Starting Member
0 Posts |
|
|
Anonymous
Starting Member
0 Posts |
|
|
Anonymous
Starting Member
0 Posts |
Posted - 11/22/2000 : 14:04:11
|
| Idiot Question: Transactions & Locking Please tell me if I understand this... In a multi-threaded environment where several connections might be calling the spPost proc, I am concerned about the results of:
SELECT @NewPostID = @@IDENTITY ...and...
UPDATE Posts SET SortOrder = SortOrder + 1 WHERE ThreadID = @ThreadID AND SortOrder >= @NextSortOrder Am I correct in assuming that the transaction will lock the other connection out, so that @@IDENTITY and the @NextSortOrder values will _not_ be updated by the other connection/thread? Alternately, if the transaction is not explicitly specified, can I assume there would be no locking, and the two threads would be simulatneously executing and corrupting the data... ie, @@IDENTITY in conn1 _could_ be the @@IDENTITY from conn2... and @NextSortOrder _could_ contain the same value in both connections...? So, the rule might be: Anytime a proc needs exclusive data, wrap it in an explicit transaction... Did I get it? - wtkwest |
 |
|
|
Anonymous
Starting Member
0 Posts |
|
|
Anonymous
Starting Member
0 Posts |
|
|
graz
Chief SQLTeam Crack Dealer
USA
4128 Posts |
|
|
Anonymous
Starting Member
0 Posts |
|
|
Anonymous
Starting Member
0 Posts |
|
|
Anonymous
Starting Member
0 Posts |
|
|
german
Starting Member
0 Posts |
|
|
EvilSyn
Starting Member
1 Posts |
Posted - 02/18/2002 : 15:36:39
|
Hi. I recently wrote a message board using the code from this... (http://www.sqlteam.com/item.asp?ItemID=1353) and i had to write in an admin for the client to be able to edit and delete the posts... Editing was no problem, but I had a heck of a time trying to figure out how to delete a post *and* it's children. I spent the better part of all day coding this and I finally finished... So in case anyone ever needs to know how to remove children posts, here's how.
Also, I'm sure i overlooked something and there's probably a *much* simpler way to do so. If this is the case, please let me know!!! Thanks
CODE ***********************************************************
set rs = server.createobject("adodb.recordset") sql = "SELECT ListServ_Members.Name, ListServ_Members.Email, ListServ_Posts.MemberID, ListServ_Posts.TopicID, ListServ_Posts.Subject, ListServ_Posts.PostID, ListServ_Posts.ThreadID, ListServ_Posts.ParentID, ListServ_Posts.PostLevel, ListServ_Posts.SortOrder, ListServ_Posts.PostDate from ListServ_Posts inner join ListServ_Members on ListServ_Members.id = ListServ_Posts.MemberID where ListServ_Posts.ThreadID = " & request("ThreadID") & " ORDER BY ListServ_Posts.SortOrder" FieldList = "PostID,ParentID" FieldsArray = split(FieldList, ",") rs.open sql, strconn, 1, 2, 1 ThreadArray = rs.GetRows(-1, 0, FieldsArray) rs.close set rs = nothing
PostIDList = "" Level = 1 PostID = cint(request("PostID")) GetRecords ThreadArray, PostID, Level PostIDList = PostIDList & PostID
response.write("<br><br>" & PostIDList) function GetRecords(RecordArray, LookingFor, Level)
if level = 20 then exit function end if
for z = 0 to ubound(RecordArray, 2) CurrentID = RecordArray(1, z) CurrentParent = RecordArray(0, z) if CurrentID = LookingFor then 'uncomment for nice debugging output 'response.write("<br>" & replace( space(Level), " ", " " ) & "Pass: " & Level & " - " & z & ", FOUND - " & CurrentID & " | GO FIND: " & CurrentParent) PostIDList = PostIDList & CurrentParent & ","
if CurrentID <> CurrentParent then GetRecords RecordArray, CurrentParent, Level + 1 end if 'uncomment for nice debugging output 'else
'uncomment for nice debugging output 'response.write("<br>" & replace( space(Level), " ", " " ) & "Pass: " & Level & " - " & z & ", NOT FOUND") end if next end function
|
 |
|
|
xstream
Starting Member
11 Posts |
|
|
xstream
Starting Member
11 Posts |
Posted - 08/30/2002 : 21:07:17
|
In the stored procedure where it says:
IF EXISTS (SELECT * FROM Posts WHERE PostLevel <= @ParentLevel AND SortOrder > @ParentSortOrder AND ThreadID = @ThreadID ) BEGIN
Shouldn't it be:
WHERE PostLevel >= @ParentLevel
If you selected all the posts in the thread that were less than the parent post level but larger than the parent sort order - wouldn't that be none of the posts?
X
|
 |
|
|
Jo-E
Starting Member
Israel
1 Posts |
Posted - 03/15/2003 : 20:49:37
|
I got this working on a production site that serves many users, and reached the conclusion that there's one thing that was overlooked and has a lot to do with performance. If you only display X root posts on every page of your discussion forum, you need to make sure the SP doesn't run on all root posts in the requested forum but only on the X posts relevant to that page, otherwise the temporary table will always contain the entire forum even though you only need several posts, which means a waste of server resources. Another thing is if you want to avoid many deadlocks make sure you create the cursor as READ_ONLY! This is how it looks now:
CREATE PROC GetChildren (@ParentID int, @forumID int, @PostLevel int, @ParentPostKey varchar(200), @forumRequestedPage int, @forumMessagesPerPage int) AS
SET NOCOUNT ON
DECLARE @NextLevel int, @Counter int, @PostKey varchar(200), @jumpRows int
SET @Counter = 1
-- Build a cursor to loop through all the kids of this post based on the fact if it's a root post or not IF @ParentID = 0 BEGIN DECLARE c1 CURSOR LOCAL SCROLL READ_ONLY FOR SELECT messageID FROM messages WHERE messageParent = @ParentID and messageForum = @forumID and deleted=0 and authorized=1 ORDER BY messageTime DESC -- since this is a root posts query, gets only the rows that are relevant to the requested page OPEN c1 IF @forumRequestedPage > 1 BEGIN SET @jumpRows = ((@forumRequestedPage - 1) * @forumMessagesPerPage) + 1 FETCH ABSOLUTE @jumpRows FROM c1 into @ParentID END ELSE BEGIN FETCH NEXT FROM c1 INTO @ParentID END
-- this loop runs on all parents until there are no more on this page or at all WHILE @@FETCH_STATUS = 0 AND @Counter <= @forumMessagesPerPage BEGIN -- Put this record in the temp table INSERT #NestedPosts (PostID, PostKey, messageLevel) VALUES (@ParentID, @PostKey, @PostLevel) SET @NextLevel = @PostLevel + 1 -- Process all the children for this post EXEC GetChildren @ParentID, @forumID, @NextLevel, @PostKey, @forumRequestedPage, @forumMessagesPerPage SET @Counter = @Counter + 1 -- And get the next record at this level FETCH NEXT FROM c1 INTO @ParentID END END ELSE BEGIN DECLARE c1 CURSOR LOCAL SCROLL READ_ONLY FOR SELECT messageID FROM messages WHERE messageParent = @ParentID and messageForum = @forumID and deleted=0 and authorized=1 -- Here we can put ASC so that the inner thread will be ordered by the order of insertion and not new comes first ORDER BY messageTime DESC -- gets all the kids for this post since it's not a root one, no need for jumping OPEN c1 FETCH NEXT FROM c1 INTO @ParentID
WHILE @@FETCH_STATUS = 0 BEGIN -- Put this record in the temp table INSERT #NestedPosts (PostID, PostKey, messageLevel) VALUES (@ParentID, @PostKey, @PostLevel) SET @NextLevel = @PostLevel + 1 -- Process all the children for this post EXEC GetChildren @ParentID, @forumID, @NextLevel, @PostKey, @forumRequestedPage, @forumMessagesPerPage SET @Counter = @Counter + 1 -- And get the next record at this level FETCH NEXT FROM c1 INTO @ParentID END END
CLOSE c1 DEALLOCATE c1
SET NOCOUNT OFF GO
Edited by - Jo-E on 03/15/2003 20:51:02 |
 |
|
|
famdylan
Starting Member
1 Posts |
Posted - 05/17/2005 : 11:31:11
|
| Okay on the same type of question say I wanted to move one of the lower replyies up to a upper level or move it to another thread how would I update all the children? Can I do this in the database or do I need to do some code in my application? |
 |
|
Topic  |
|