使用Python和Mysql连接器发送空间数据
使用Mysql连接器和Python,我试图将最简单的空间数据形式(点数据类型)传递给我的Mysql数据库。使用mysql连接器,Option1中的“execute”函数可以工作,而Option2中的同一命令无法工作,这会导致“您的SQL语法有错误”错误 你能告诉我为什么选项2“mycursor.execute(sql,val)”会给我一个错误吗使用Python和Mysql连接器发送空间数据,python,mysql,spatial,mysql-connector,spatial-data,Python,Mysql,Spatial,Mysql Connector,Spatial Data,使用Mysql连接器和Python,我试图将最简单的空间数据形式(点数据类型)传递给我的Mysql数据库。使用mysql连接器,Option1中的“execute”函数可以工作,而Option2中的同一命令无法工作,这会导致“您的SQL语法有错误”错误 你能告诉我为什么选项2“mycursor.execute(sql,val)”会给我一个错误吗 import mysql.connector from Functions import * mydb = mySqlConnection() mycu
import mysql.connector
from Functions import *
mydb = mySqlConnection()
mycursor = mydb.cursor()
Latitude=5.245 # Values are random
Longitude=1.66 # Values are random
Location = "ST_GeomFromText('POINT("+str(Latitude)+" "+str(Longitude)+")')"
#OPTION 1 - WORKS
sql = "INSERT INTO test (Location) VALUES ("+Location+")"
mycursor.execute(sql)
#OPTION 2 - DOES NOT WORK
sql = "INSERT INTO test (Location) VALUES (%s)"
val = (Location)
mycursor.execute(sql, val)
mydb.commit()
任何想法都将受到赞赏。非常感谢
最好的,
Alex选项2插入语法中的
%s
值是什么?%s
表示通过val参数的值。请参考下面链接中的示例实际上,我想知道%s
的翻译值是多少。完整的错误消息是什么?