gpt4 book ai didi

python - 为什么我不能在 MYSQL 中执行此 INSERT? ( python MySQLdb)

转载 作者:搜寻专家 更新时间:2023-10-30 21:48:31 25 4
gpt4 key购买 nike

这是我之前提出的这个问题的后续: Why can't I insert into MySQL?

这个问题部分解决了它。现在我正在用 Python 做它,但它不起作用 :(

cursor.execute("INSERT INTO life(user_id, utm)  values(%s,PointFromWKB(point(%s,%s)))",the_user_id, utm_easting, utm_northing)

我什至做了 float(utm_easting) 和 float(utm_northing)

编辑:这是错误:

execute() 最多接受 3 个参数(给定 5 个)

最佳答案

来自 here (pdf) :

Following the statement string argument to execute(), provide a tuple containing the values to be bound to the placeholders, in the order they should appear within the string. If you have only a single value x, specify it as (x,) to indicate a single-element tuple.

tl;博士:

cursor.execute("""INSERT INTO life(user_id, utm) 
values(%s,PointFromWKB(point(%s,%s)))""",
(the_user_id, utm_easting, utm_northing))

编辑:您也可以将列表作为 execute() 的第二个参数传递。

cursor.execute("""INSERT INTO life(user_id, utm) 
values(%s,PointFromWKB(point(%s,%s)))""",
[the_user_id, utm_easting, utm_northing])

关于python - 为什么我不能在 MYSQL 中执行此 INSERT? ( python MySQLdb),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2269776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com