Mysql更新语法错误Python

时间:2012-05-07 17:14:58

标签: python sql-update mysql-python

我一直在关注此前的答案,但我仍然遇到语法错误:

Stack Overflow Answer

    cursor.execute ("""
   UPDATE tblTableName
   SET Year=%s, Month=%s, Day=%s, Hour=%s, Minute=%s
   WHERE Server=%s
   """, (Year, Month, Day, Hour, Minute, ServerID))

我的代码是:

def postToMySQL(data,fieldname,table,col):
if fieldname == "Year":
    sql = "INSERT INTO " + table + " ("+ fieldname + ") VALUES (%s)"
    c.execute(sql, data)
else:
    c.execute ("""
   UPDATE %s
   SET US=%s
   WHERE ID=%s
    """, (table, data, col))

然后表格如下:

Stack Overflow Answer

语法错误是:

  

_mysql_exceptions.ProgrammingError:(1064 ....''OilProvedReservesHistory'Set US = '36 .533'WHERERE ID = 1'at line 1

你能发现错误吗? ?谢谢

1 个答案:

答案 0 :(得分:1)

应该是这样的,没有引号

SET US = '36 .533'

你可以试试这个:

UPDATE %s
   SET US=%s
   WHERE ID=%s