📄 cs_forums_post.prc
字号:
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_forums_Post]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[cs_forums_Post]
GO
CREATE PROCEDURE [dbo].cs_forums_Post
/*
Procedure for getting basic information on a single post.
*/
(
@PostID int,
@UserID int,
@TrackViews bit,
@SettingsID int
) AS
SET Transaction Isolation Level Read UNCOMMITTED
DECLARE @NextThreadID int
DECLARE @PrevThreadID int
DECLARE @ThreadID int
DECLARE @SectionID int
DECLARE @SortOrder int
DECLARE @IsApproved bit
SELECT
@ThreadID = ThreadID,
@SectionID = SectionID,
@SortOrder=SortOrder,
@IsApproved = IsApproved
FROM
cs_Posts (nolock)
WHERE
PostID = @PostID and SettingsID = @SettingsID
-- Is the Forum 0 (If so this is a private message and we need to verify the user can view it
IF @SectionID = 0
BEGIN
IF NOT EXISTS (SELECT UserID FROM cs_PrivateMessages WHERE UserID = @UserID AND ThreadID = @ThreadID)
RETURN
END
-- Get the previous and next thread id
EXEC cs_Thread_PrevNext @ThreadID, @SectionID, @SettingsID, @NextThreadID OUTPUT, @PrevThreadID OUTPUT
DECLARE @TrackingThread bit
IF @TrackViews = 1
BEGIN
-- Update the counter for the number of times this post is viewed
UPDATE cs_Posts SET TotalViews = (TotalViews + 1) WHERE PostID = @PostID and SettingsID = @SettingsID
UPDATE cs_Threads SET TotalViews = (TotalViews + 1) WHERE ThreadID = @ThreadID and SettingsID = @SettingsID
END
-- If @UserID is 0 the user is anonymous
IF @UserID > 0 AND @IsApproved = 1
BEGIN
-- Mark the post as read
-- *********************
IF NOT EXISTS (SELECT ThreadID FROM cs_ThreadsRead WHERE ThreadID = @ThreadID AND UserID = @UserID and SettingsID = @SettingsID)
INSERT INTO cs_ThreadsRead (UserID, ThreadID, SectionID, SettingsID) VALUES (@UserID, @ThreadID, @SectionID, @SettingsID)
END
-- get the anonymous user id for this site
if( @UserID = 0 )
BEGIN
exec cs_GetAnonymousUserID @SettingsID, @UserID output
END
IF EXISTS(SELECT ThreadID FROM cs_TrackedThreads (nolock) WHERE ThreadID = @ThreadID AND UserID=@UserID)
SELECT @TrackingThread = 1
ELSE
SELECT @TrackingThread = 0
SELECT
P.PostID, P.ThreadID, P.ParentID, P.PostAuthor, P.UserID, P.SectionID, P.PostLevel, P.SortOrder, P.Subject, P.PostDate, P.IsApproved,
P.IsLocked, P.IsIndexed, P.TotalViews, P.Body, P.FormattedBody, P.IPAddress, P.PostType, P.EmoticonID, P.SettingsID, P.AggViews,
P.PropertyNames as PostPropertyNames, P.PropertyValues as PostPropertyValues,
P.PostConfiguration,
U.*, P.PostAuthor as [Username],
T.ThreadDate,
T.StickyDate,
T.IsLocked,
T.IsSticky,
T.RatingSum,
T.TotalRatings,
HasRead = 0,
EditNotes = (SELECT EditNotes FROM cs_PostEditNotes WHERE PostID = P.PostID),
IndexInThread = (SELECT Count(PostID) FROM cs_Posts P1 WHERE IsApproved = 1 AND ThreadID = @ThreadID AND SortOrder <= (SELECT SortOrder FROM cs_Posts where PostID = @PostID)),
AttachmentFilename = ISNULL ( (SELECT [FileName] FROM cs_PostAttachments WHERE PostID = P.PostID), ''),
IsModerator = (SELECT Count(*) FROM cs_Moderators WHERE UserID = U.cs_UserID),
Replies = (SELECT COUNT(*) FROM cs_Posts P2 (nolock) WHERE P2.ParentID = P.PostID AND P2.PostLevel != 1),
PrevThreadID = @PrevThreadID,
NextThreadID = @NextThreadID,
UserIsTrackingThread = @TrackingThread
FROM
cs_Posts P,
cs_Threads T,
cs_vw_Users_FullUser U
WHERE
P.PostID = @PostID AND
P.ThreadID = T.ThreadID AND
P.UserID = U.cs_UserID and P.SettingsID = @SettingsID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
grant execute on [dbo].cs_forums_Post to public
go
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -