Skip to content

Commit 09cf4fe

Browse files
committed
Add support for SRID column attribute for GEOMETRY types
1 parent cf050bf commit 09cf4fe

File tree

6 files changed

+4933
-4876
lines changed

6 files changed

+4933
-4876
lines changed

ast.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,8 @@ type ColumnType struct {
13881388
Unsigned BoolVal
13891389
Zerofill BoolVal
13901390
Scale *SQLVal
1391+
// SRID is an optional spatial reference identifier for spatial column types.
1392+
SRID *SQLVal
13911393

13921394
// Text field options
13931395
Charset string
@@ -1434,6 +1436,9 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
14341436
if ct.Zerofill {
14351437
opts = append(opts, keywordStrings[ZEROFILL])
14361438
}
1439+
if ct.SRID != nil {
1440+
opts = append(opts, keywordStrings[SRID], String(ct.SRID))
1441+
}
14371442
if ct.Charset != "" {
14381443
opts = append(opts, keywordStrings[CHARACTER], keywordStrings[SET], ct.Charset)
14391444
}

parse_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,19 @@ func TestCreateTable(t *testing.T) {
25042504
}
25052505
}
25062506

2507+
validSpatialSRIDDDL := []string{
2508+
"create table tbl_geo_a (col_a point srid 4326 not null, spatial index idx_geo_a (col_a))",
2509+
"create table tbl_geo_b (col_a geometry srid 0, col_b linestring srid 3857, col_c multipolygon)",
2510+
"alter table tbl_geo_c add column col_a point srid 4326",
2511+
"alter table tbl_geo_d modify column col_a multipoint srid 4326 not null",
2512+
}
2513+
for _, sql := range validSpatialSRIDDDL {
2514+
tree, err := Parse(sql)
2515+
if tree == nil || err != nil {
2516+
t.Errorf("Parse unexpectedly rejected spatial SRID DDL %s: %v", sql, err)
2517+
}
2518+
}
2519+
25072520
sql := "create table t garbage"
25082521
if _, err := Parse(sql); err == nil {
25092522
t.Errorf("Parse unexpectedly accepted input %s", sql)
@@ -2853,6 +2866,19 @@ func TestCreateTable(t *testing.T) {
28532866
}
28542867
}
28552868

2869+
invalidSpatialSRIDSQL := []string{
2870+
"create table tbl_geo_bad1 (col_a point srid)",
2871+
"create table tbl_geo_bad2 (col_a point srid '4326')",
2872+
"alter table tbl_geo_bad3 add column col_a linestring srid",
2873+
"alter table tbl_geo_bad4 modify column col_a geometry srid ident_srid",
2874+
}
2875+
for _, sql := range invalidSpatialSRIDSQL {
2876+
tree, err := Parse(sql)
2877+
if tree != nil || err == nil {
2878+
t.Errorf("Parse unexpectedly accepted input %s", sql)
2879+
}
2880+
}
2881+
28562882
invalidColumnAttributeDupSQL := []string{
28572883
"alter table tbl_attr_bad1 add column col_a int default 1 default 2",
28582884
"alter table tbl_attr_bad2 add column col_a int null not null",

0 commit comments

Comments
 (0)