这是我的代码:
postconn = mysql.connector.connect(user='root', password='Infinity8', host='127.0.0.1', database='geodb')
postcursor = postconn.cursor() # creating cursor
....
print ("currently selected ID: ", mydata[0])
sql_update_flag = """ UPDATE REQUESTS SET fl_ready = {0} WHERE request_id={1} """.format(set_flag, current_id)
print (sql_update_flag)
print ("Before commit")
currSrc.execute(sql_update_flag)
print "after commit"
connSrc.commit()
执行后,下一次登录失败:
('currently selected ID: ', 10)
UPDATE REQUESTS SET fl_ready = 11 WHERE request_id=10
Before commit
Traceback (most recent call last):
File "C:\monitoring\GetRequest.py", line 168, in <module>
main()
File "C:\monitoring\GetRequest.py", line 164, in main
SyncRequest(postconn, fireconn)
File "C:\monitoring\GetRequest.py", line 92, in SyncRequest
currSrc.execute(sql_update_flag)
File "C:\Python27\ArcGIS10.2\lib\site-packages\mysql\connector\cursor.py", line 485, in execute
self._connection.handle_unread_result()
File "C:\Python27\ArcGIS10.2\lib\site-packages\mysql\connector\connection.py", line 1057, in handle_unread_result
raise errors.InternalError("Unread result found")
mysql.connector.errors.InternalError: Unread result found
问题似乎在这里:
currSrc.execute(sql_update_flag)
但我做错了什么?
答案 0 :(得分:0)
您必须先提取所有行,然后再执行其他任何操作。
您可以这样做:
...
# do SELECT
postcursor.execute("SELECT ...")
rows = postcursor.fetchall()
...
# do UPDATE