pyODBC语句似乎正在运行,但不影响制表符

2024-10-03 11:13:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下脚本运行

from os import getenv
import pyodbc
import os
import sys

cnxn = pyodbc.connect('''
DRIVER={ODBC Driver 13 for SQL Server};SERVER=myServer\SQLEXPRESS;
DATABASE=myTable;UID=myID;PWD=myPassword''')

cursor = cnxn.cursor() #makes connection
cursor.execute("""

            UPDATE ShowroomCal
                SET ShowroomCal.isbusy = 'Yes'
            FROM ShowroomCal
                JOIN calendarbookings on calendarbookings.date=showroomcal.style112 AND calendarbookings.showroom=ShowroomCal.showroom_name
                WHERE CalendarBookings.date = showroomcal.style112 and ShowroomCal.Year='2018'
                """) #runs update statement

row_count = cursor.rowcount #counts afrfected rows
status_msg = "result returned. {} row(s) affected."
print(status_msg.format(row_count)) #prints affected rows

cnxn.close()

notebook单元格返回“3行受影响”。然而,在sqlexpress中查看时,正在更新的表没有更改。在

从那以后,我在一个查询窗口中独立地从SQLServer管理中运行了这条语句,它立即改变了可能受到影响的三行,因此我知道表中的数据是存在的,并且该语句是有效的——至少从SQL的角度来看是这样的。在

有人能从Python的角度发现错误吗?在


Tags: importsqldateoscountcursorrowsrow