У меня есть хранимая процедура в базе данных 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 в моем клиенте SQL Operations Studio:
VideoSearchThorough 'search string', 0, 20
.. возвращаются только 20 записей.Мне нужно только 20 записей, так как я передаю 20
в качестве предела (третий параметр, предоставленный для хранимой процедуры VideoSearchThorough
).
Однако при использовании pytds
возвращается всего 84 записи.модуль в Python 3.7, почему разница?