Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytds调用的MSSQL存储过程返回的记录太多_Python_Sql Server_Python 3.x_Sql Server 2008 - Fatal编程技术网

Python pytds调用的MSSQL存储过程返回的记录太多

Python pytds调用的MSSQL存储过程返回的记录太多,python,sql-server,python-3.x,sql-server-2008,Python,Sql Server,Python 3.x,Sql Server 2008,我在MSSQL数据库中有一个存储过程,如下所示: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[VideoSearchThorough] ( @SearchString NVARCHAR(4000) = '' , @Offset INT = 0 , @Limit INT = 100 , @UserId INT = 0 , @ProviderId INT = NULL , @S

我在MSSQL数据库中有一个存储过程,如下所示:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[VideoSearchThorough]
(
  @SearchString NVARCHAR(4000) = ''
  , @Offset INT = 0
  , @Limit INT = 100
  , @UserId INT = 0
  , @ProviderId INT = NULL
  , @StatusType INT = 0
  , @StartDate datetime = NULL
  , @EndDate datetime = NULL
  , @UseUpdatedDate bit = 0
  , @PltValue INT = NULL
)
AS
BEGIN
    DECLARE @OrderClause VARCHAR(200) = 'CreatedDate DESC'

    IF @Limit IS NULL OR @Limit > 100 SET @Limit = 100

    CREATE TABLE #tmpsrch(
      VideoId BIGINT,
      UserId INT,
      VideoUrl VARCHAR(500),
      Title VARCHAR(1000),
      Description VARCHAR(5000),
      CreatedDate datetime,
      EffectiveDate datetime,
      ExpirationDate datetime,
      Height INT,
      Width INT,
      Duration decimal(10, 2),
      ThumbnailUrl VARCHAR(200),
      Keywords VARCHAR(200),
      IsEnabled bit,
      IsDeleted bit,
      ProviderId INT,
      ProviderName VARCHAR(200),
      ProviderLogo VARCHAR(200),
      ProviderTrackingGroup INT,
      ProviderIsMediaSource bit,
      ProviderContentIsPrivate bit
    )

    INSERT INTO #tmpsrch(VideoId, UserId, VideoUrl, Title, Description, CreatedDate, EffectiveDate, ExpirationDate, Height, Width, Duration, ThumbnailUrl, Keywords, IsEnabled, IsDeleted, ProviderId, ProviderName, ProviderLogo, ProviderTrackingGroup, ProviderIsMediaSource, ProviderContentIsPrivate)
    EXEC VideoSearch @SearchString=@SearchString, @MatchType=0

    IF (SELECT COUNT(*) FROM #tmpsrch (NOLOCK)) = 0
    INSERT INTO #tmpsrch(VideoId, UserId, VideoUrl, Title, Description, CreatedDate, EffectiveDate, ExpirationDate, Height, Width, Duration, ThumbnailUrl, Keywords, IsEnabled, IsDeleted, ProviderId, ProviderName, ProviderLogo, ProviderTrackingGroup, ProviderIsMediaSource, ProviderContentIsPrivate)
    EXEC VideoSearch @SearchString=@SearchString, @MatchType=1

    IF (SELECT COUNT(*) FROM #tmpsrch (NOLOCK)) = 0
    INSERT INTO #tmpsrch(VideoId, UserId, VideoUrl, Title, Description, CreatedDate, EffectiveDate, ExpirationDate, Height, Width, Duration, ThumbnailUrl, Keywords, IsEnabled, IsDeleted, ProviderId, ProviderName, ProviderLogo, ProviderTrackingGroup, ProviderIsMediaSource, ProviderContentIsPrivate)
    EXEC VideoSearch @SearchString=@SearchString, @MatchType=2

    SELECT TOP (@Limit) *, (SELECT COUNT(*) FROM #tmpsrch (NOLOCK)) AS ResultsAvailable FROM (
        SELECT
            ROW_NUMBER() OVER (ORDER BY CreatedDate DESC) AS rowId,
            *
        FROM #tmpsrch
    ) AS results
    WHERE results.rowId > @Offset

    DROP TABLE #tmpsrch
END

GO
在我的python 3代码中,我通过
pytds
模块调用此存储过程:

with pytds.connect(db_server, db_name, db_user, db_pass) as connection, connection.cursor() as cursor:
    cursor.callproc('VideoSearchThorough', ['search string', 0, 20])
    response = cursor.fetchall()
    result = []
    for rowData in response:
        row = {}
        for columnIndex, columnData in enumerate(cursor.description):
            row[columnData[0]] = rowData[columnIndex]
        result.append(row)

    return result # This contains 84 result records
但是,当我在SQL Operations Studio客户端中执行以下SQL时:

VideoSearchThorough 'search string', 0, 20
..只返回20条记录。当我通过
20
作为限制时,我只需要20条记录(提供给
videosearch
存储过程的第三个参数)


但是,在使用Python 3.7中的
pytds
模块时,总共返回84条记录,为什么会有差异

我看不出Python代码中设置@Limit变量的地方:如果没有设置,则使用默认值100,但只返回87条记录。

您没有向过程发送限制。默认值为100