• cs_forums_threads_ThreadsRead///cs_fourm_Feedback_Get


    ALTER   PROCEDURE [dbo].[cs_fourm_Feedback_Get]
    (
         
    @SectionID int
        ,
    @ParentID int = null
        ,
    @PostType int = 12 -- 1 and 3 are image and comment types for gallery 
        ,@Approved int = null   /*1和3是*/
        ,
    @UsePaging bit = 0
        ,
    @PageIndex int = 0
        ,
    @PageSize int = 0
        ,
    @SettingsID int
        ,
    @TotalRecords int output
    )
    AS
    SET Transaction Isolation Level Read UNCOMMITTED
     
    /*设置事务隔离级别,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 (@ParentID is null) )
            
    AND ( (@Approved=P.IsApproved) OR (@Approved is null) )
              
    /*查询同一类型的帖子的数量(是对论坛,博客和相册来分的,上面的参数有说到.
                    如果ApplicationPostType和输入的类型相同则查询出来)
    */


    IF @UsePaging = 0
        
    ---如果无进行分页的话
    BEGIN
        
    -- Just select all the feedback for the blog
            -- 应该是博客的所有评论
        SELECT
             P.PostID
            ,P.PostAuthor
            ,P.Subject
            ,P.PostDate
            ,P.IsApproved
            ,
    null as 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 (@ParentID is null) )
            
    AND ( (@Approved=P.IsApproved) OR (@Approved is null) )
        
    ORDER BY
            P.PostDate 
    DESC




    END
    ELSE -- We need to get paged data
         -- 获取分页的数据,
    BEGIN
        
    -- We'll Sort by newest first
            -- 声明一些用于分页的变量
        DECLARE @PageLowerBound int
        
    DECLARE @PageUpperBound int
        
    DECLARE @RowsToReturn int

        
    -- First set the rowcount
            -- 首先设置返回的行数(返回的是两页的数据量)
        SET @RowsToReturn = @PageSize * (@PageIndex + 1)
        
    SET ROWCOUNT @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 @PageIdx TABLE
        (
            IndexID 
    int IDENTITY (11NOT NULL,
            PostID 
    int
        )

        
    INSERT INTO
            
    @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 (@ParentID is null) )
            
    AND ( (@Approved=P.IsApproved) OR (@Approved is null) )
        
    ORDER BY
             P.PostDate 
    DESC
            ,P.PostID 
    DESC



        
    -- now return the results:
            -- 此处才是返回真正的结果,是经过计算的,只显示一页的数据
        SELECT
             P.PostID
            ,P.PostAuthor
            ,P.Subject
            ,P.PostDate
            ,P.IsApproved
            ,
    null as 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
            
    */

                  
    /*后面没用到那个定义的返回行数的参数,不知道为什么呢.*/

        
    ORDER BY
             P.PostDate 
    DESC
            ,P.PostID 
    DESC


    END

    END
    cs_forums_threads_ThreadsRead
  • 相关阅读:
    SqlServer Function 实例
    技术清单
    SQLSERVER 链接服务器执行存储过程
    SQLSERVER 链接服务器
    Oracle 新手语法记录
    MarkDown 语法备份
    C# WebAPI小记
    Rabbit MQ 学习 (二)
    Rabbit MQ 学习 (一)Window安装Erlang环境
    [vue2,nodejs,echarts,json]调查问卷
  • 原文地址:https://www.cnblogs.com/ruanbl/p/509730.html
Copyright © 2020-2023  润新知