ALTERPROCEDURE[dbo].[cs_fourm_Feedback_Get] ( @SectionIDint ,@ParentIDint=null ,@PostTypeint=12-- 1 and 3 are image and comment types for gallery ,@Approvedint=null/**//*1和3是*/ ,@UsePagingbit=0 ,@PageIndexint=0 ,@PageSizeint=0 ,@SettingsIDint ,@TotalRecordsint output ) AS SETTransactionIsolationLevelReadUNCOMMITTED /**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁, 也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更 改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有 语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/ BEGIN -- Return Fields: -- 返回的一些字段 -- PostID, PostAuthor, Subject, PostDate, IsApproved, TitleUrl, Body SELECT @TotalRecords=Count( P.PostID ) FROM cs_Posts P (nolock) WHERE P.SectionID =@SectionID AND (P.SettingsID =@SettingsID) AND ( ( P.ApplicationPostType &@PostType ) <>0 ) AND ( (@ParentID=P.ParentID) OR (@ParentIDisnull) ) AND ( (@Approved=P.IsApproved) OR (@Approvedisnull) ) /**//*查询同一类型的帖子的数量(是对论坛,博客和相册来分的,上面的参数有说到. 如果ApplicationPostType和输入的类型相同则查询出来)*/ IF@UsePaging=0 ---如果无进行分页的话 BEGIN -- Just select all the feedback for the blog -- 应该是博客的所有评论 SELECT P.PostID ,P.PostAuthor ,P.Subject ,P.PostDate ,P.IsApproved ,nullas TitleUrl ,P.Body ,P.ApplicationPostType FROM cs_Posts P (nolock) WHERE P.SectionID =@SectionID AND P.SettingsID =@SettingsID AND ( ( P.ApplicationPostType &@PostType ) <>0 ) AND ( (@ParentID=P.ParentID) OR (@ParentIDisnull) ) AND ( (@Approved=P.IsApproved) OR (@Approvedisnull) ) ORDERBY P.PostDate DESC END ELSE-- We need to get paged data -- 获取分页的数据, BEGIN -- We'll Sort by newest first -- 声明一些用于分页的变量 DECLARE@PageLowerBoundint DECLARE@PageUpperBoundint DECLARE@RowsToReturnint -- First set the rowcount -- 首先设置返回的行数(返回的是两页的数据量) SET@RowsToReturn=@PageSize* (@PageIndex+1) SETROWCOUNT@RowsToReturn -- Set the page bounds ---------- 设置页面绑定 SET@PageLowerBound=@PageSize*@PageIndex SET@PageUpperBound=@PageLowerBound+@PageSize+1 -- Create a temp table to store the select results -- 创建临时表,为分页而设计的,主要是主键ID用与和分页的变量关联, DECLARE@PageIdxTABLE ( IndexID intIDENTITY (1, 1) NOTNULL, PostID int ) INSERTINTO @PageIdx (PostID) SELECT P.PostID FROM cs_Posts P (nolock) WHERE p.SectionID =@SectionID AND p.SettingsID =@SettingsID AND ( ( P.ApplicationPostType &@PostType ) <>0 ) AND ( (@ParentID=P.ParentID) OR (@ParentIDisnull) ) AND ( (@Approved=P.IsApproved) OR (@Approvedisnull) ) ORDERBY P.PostDate DESC ,P.PostID DESC -- now return the results: -- 此处才是返回真正的结果,是经过计算的,只显示一页的数据 SELECT P.PostID ,P.PostAuthor ,P.Subject ,P.PostDate ,P.IsApproved ,nullas TitleUrl ,P.Body ,P.ApplicationPostType FROM cs_Posts P (nolock) ,@PageIdx I WHERE P.PostID = I.PostID AND ( ( P.ApplicationPostType &@PostType ) <>0 ) AND I.IndexID >@PageLowerBound AND I.IndexID <@PageUpperBound /**//* -- These lines are redudant, since they were already checked in the above query: and P.SettingsID = @SettingsID AND p.SectionID = @SectionID */ /**//*后面没用到那个定义的返回行数的参数,不知道为什么呢.*/ ORDERBY P.PostDate DESC ,P.PostID DESC END END
cs_forums_threads_ThreadsRead ALTERprocedure[dbo].cs_forums_threads_ThreadsRead ( @SectionIDasint, @UserIDasint, @SettingsIDasint ) AS SETTransactionIsolationLevelReadUNCOMMITTED /**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁, 也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更 改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有 语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/ DECLARE@ReadAfterint /**//*不知道是不是关于主题被阅读的次数或者什么*/ SELECT @ReadAfter= MarkReadAfter FROM cs_SectionsRead WHERE UserID =@UserIDAND SectionID =@SectionIDAND SettingsID =@SettingsID IF@ReadAfterISNOTNULL SELECT ThreadID =@ReadAfter ELSE SELECT ThreadID =0 IF@SectionID=-1 BEGIN SELECTDISTINCT ThreadID FROM cs_ThreadsRead WHERE SettingsID =@SettingsID AND UserID =@UserID END ELSE BEGIN SELECTDISTINCT ThreadID FROM cs_ThreadsRead WHERE UserID =@UserIDAND SectionID =@SectionIDAND SettingsID =@SettingsID END