2017-10-12 88 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() 

如果未設置自動提交,則必須自己提交。

相關問題