AttributeError: type object 'Global' has no attribute 'cursor'

AttributeError: type object 'Global' has no attribute 'cursor'

我在 运行 pyodbc 中的以下数据库查询时出现以下错误。

查询

DECLARE  @TempTable Table (Flag int)
DECLARE @intFlag INT
DECLARE @intFlag1 VARCHAR(50);
SET NOCOUNT ON
SET @intFlag1 = 'foo'
SET @intFlag=(select a.fooID from foo a
where a.fooName=@intFlag1)
INSERT INTO @TempTable SELECT @intFlag
WHILE (@intFlag >=0)
BEGIN
 set @intFlag=(select a.basefooId from foo a
 join foo b on a.basefooId=b.fooID
 where a.fooID=@intFlag)
 INSERT INTO @TempTable SELECT @intFlag
 END
 SELECt * from @TempTable

以上查询在 sql 服务器中运行良好。

数据库

connection = pyodbc.connect(super().database_config())
        Global.connection = connection.cursor()  
result = list(Global.connection.execute(query))

错误:

while Global.cursor.nextset():  # NB: This always skips the first resultset
AttributeError: type object 'Global' has no attribute 'cursor'

注意:我知道,许多此类问题已经在同一个论坛中提出和回答,但显然我根据这些指导进行的修复没有产生预期的结果。可能是我实施错误。有人可以说明如何修复它吗?

在 pyodbc 的查询之上保持 SET NOCOUNT ON 后问题得到解决。