在Python中将None作为Null传递给MySQL

时间:2017-02-19 13:43:17

标签: python mysql stored-procedures

我有样品:

args["test"] = None

try:
  with self.connection.cursor(MySQLdb.cursors.DictCursor) as cursor:
  cursor.callproc('mystoredproc',[str(args["test"])])
  self.connection.commit()
  result = {"status": True, "reason": "", "result": json.loads(json.dumps(cursor.fetchone(), cls=DateTimeEncoder))}
except (MySQLdb.Error, MySQLdb.Warning) as e:
  print("ERROR: {}".format(e))
  result = {"status": False, "reason": "Insert Failed", "result": "ERROR: {}".format(e)}
finally:
  # self.DestroyConnection()
  pass

问题很简单:

如何将None作为null传递给上方? 可以不转换价值吗?

如果我运行该代码,它会返回我:

  

错误:(1366,“不正确的十进制值:'无',用于列'test'at   第1行“)

它假设在DB

中将值设置为NULL

谢谢!

0 个答案:

没有答案