我有一个string以十六进制表示多边形的对象,我想将其保存到mysql数据库中。我使用了 `` 如此处所述。这是我用来生成多边形的方法:
func GetPolygon(coordinates [][]geom.Coord) (string, error) {
unitSquare := geom.NewPolygon(geom.XY).MustSetCoords(coordinates)
polygon, err := wkb.Marshal(unitSquare, wkb.NDR)
if err != nil {
fmt.Printf("wkb marshal error: %s\n", err.Error())
return "", err
}
polygonHex := hex.Dump(polygon)
return polygonHex, nil
}
这就是我生成查询的方式:
insertQuery := fmt.Sprintf(`INSERT INTO my_table (polygon) VALUE (ST_GeomFromWKB(X'%v'))`, poly)
但是当我执行查询时,我得到:
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'X'00000000 01 03 00 00 00 01 00 00 00 92 00 00 00 ff ff ff |................|' at line 1
慕田峪7331174
相关分类