2017-10-12 87 views
1

enter image description herepymssql - SELECT作品,但更新不

import pymssql 
import decimal 

CONN = pymssql.connect(server='1233123123', user='s123', password='sa1231231', database='DBforTEST') 
CURSOR = CONN.cursor() 
"""it is good code. here is no problem""" 
CURSOR.execute("SELECT ttt from test where w=2") 
ROW = CURSOR.fetchone() 
tmp = list() 
tmp.append(ROW) 
if ROW is None: 
    print("table has nothing") 
else: 
    while ROW: 
     ROW = CURSOR.fetchone() 
     tmp.append(ROW) 
print(tmp) 
"""it works!""" 

CURSOR.execute(""" 
       UPDATE test 
       SET 
       w = 16 
       where ttt = 1 
       """) 
"it doesnt works" 

我使用python 3.5 pymssql。

在我的代码中,SELECT状态有效,所以我可以保证连接是完美的。
但是UPDATE状态在Python中不起作用。
相同的代码在SSMS中起作用。

什么问题?
我猜SELECT状态是只读的,所以DB可以提供数据,但UPDATE正在修改DB,所以DB会阻塞它。

我该如何解决?

回答

2
CONN.commit() 

如果未设置自动提交,则必须自己提交。

相关问题