Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python和Mysql连接器发送空间数据_Python_Mysql_Spatial_Mysql Connector_Spatial Data - Fatal编程技术网

使用Python和Mysql连接器发送空间数据

使用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

使用Mysql连接器和Python,我试图将最简单的空间数据形式(点数据类型)传递给我的Mysql数据库。使用mysql连接器,Option1中的“execute”函数可以工作,而Option2中的同一命令无法工作,这会导致“您的SQL语法有错误”错误

你能告诉我为什么选项2“mycursor.execute(sql,val)”会给我一个错误吗

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
的翻译值是多少。完整的错误消息是什么?