【发布时间】:2012-03-17 18:28:10
【问题描述】:
我已经用 MySQLdb 创建了一个数据库。 在数据库中,我有一个名为 student 的表,其中包含列:
id(is int),
id_user(is int),
f_name(is str),
l_name(is str)
我用函数更新更新一行。 我的代码如下:
def UpdateUser(self,e):
self.checkid_user=int(self.updateid[0]) #ok there
self.c2name=self.name.GetValue() #this is from a textctrl in wxpython
self.c2lastname=self.lastname.GetValue()#this is from a textctrl in wxpython
ne=self.c2name.encode("utf-8")#greek word
fe=self.c2lastname.encode("utf-8")#greek word
f="'"+str(ne)+"'"
l="'"+str(fe)+"'"
print f #ok
print l #ok
db=mdb.connect(host="localhost",use_unicode="True",charset="utf8",user="root",passwd="root",db="test")
cursor = db.cursor()
sql="""SELECT id_user FROM student"""
try:
# Execute the SQL command
cursor.execute(sql)
# Commit your changes in the database
db.commit()
except:
# Rollback in case there is any error
db.rollback()
rows = cursor.fetchall()
for row in rows:
r=int(row[0])
if r==self.checkid_user: #ok there
sql2 = """UPDATE student
SET f_name=%s,l_name=%s
WHERE id_user=%s"""
# Execute the SQL command
cursor.execute(sql2(f,l,r))
# Commit your changes in the database
db.commit()
db.rollback()
# disconnect from server
db.close()
当我运行该函数时,出现以下错误:
typeerror 'str' 对象不可调用我使用 f 和 l 来调用,但什么都没有。
我需要一些帮助来解决这个问题。谢谢!
【问题讨论】:
-
发布其余的错误消息。它会告诉您错误的实际位置。
标签: python mysql wxpython mysql-python wxwidgets