Python MySQLdb更新查询失败 [英] Python MySQLdb update query fails
问题描述
好的.我在这里建立了一个mysql查询浏览器,例如navicat.使用MySQLdb执行查询.
Okay. I've built here a mysql query browser, like navicat. Using MySQLdb to perform queries.
这是奇怪的部分.当我通过程序运行查询(使用MySQLdb)时,它给我成功,受影响的行= 1,但是当我在phpmyadmin中查看该查询时,该值没有改变.
Here's the weird part. When i run the query through the program(using MySQLdb), it gives me success, affected rows = 1, but when i look at it in phpmyadmin, the value hasn't changed.
因此,在执行查询之前,我先将其打印出来,然后复制并粘贴到phpmyadmin的查询窗口中,然后按一下go即可.长话短说,更新查询不起作用,但是当我复制并粘贴到phpmyadmin中时,它就起作用了.
so before i perform the query, i print it out, copy and paste into phpmyadmin's query window, hit go and it works. So long story short, update query isn't working, but when i copy and paste into phpmyadmin, it works.
self.tbl.sql.use(self.tbl.database) # switches to correct database. I've printed this and it uses the corrected db
if self.tbl.sql.execute(query) == True:
print sql_obj.rows_affected() # returns 1 (since i only do 1 query)
这是SQL类的一部分
def execute(self, query):
try:
self.cursor.execute(query)
return True
except MySQLdb.ProgrammingError as error:
print "---->SQL Error: %s" % error
return False
except MySQLdb.IntegrityError as e:
print "--->SQL Error: %s" % e
return False
那么有什么想法可能发生吗?
So any ideas what could be happening?
推荐答案
只是一个猜测:也许Python中的代码正在事务中运行,并且可能需要显式提交事务?
Just a guess: Perhaps the code in Python is running within a transaction, and the transaction might need to be explicitly committed?
有一个可能相关的MySQLdb常见问题解答中的条目.
这篇关于Python MySQLdb更新查询失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!