Skip to content

Commit

Permalink
Add SRID support
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Dec 7, 2022
1 parent 1bcc32d commit e2c7f4c
Show file tree
Hide file tree
Showing 9 changed files with 9,720 additions and 9,673 deletions.
3 changes: 3 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,9 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o
ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrTableCantHandleFt.GenWithStackByArgs())
case ast.ColumnOptionCheck:
ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrUnsupportedConstraintCheck.GenWithStackByArgs("CONSTRAINT CHECK"))
case ast.ColumnOptionSrid:
col.AddFlag(mysql.SridFlag)
col.Srid = v.Srid
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,9 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
if len(col.Comment) > 0 {
buf.WriteString(fmt.Sprintf(" COMMENT '%s'", format.OutputFormat(col.Comment)))
}
if mysql.HasSridFlag(col.GetFlag()) {
buf.WriteString(fmt.Sprintf(" /*!80003 SRID %d */", col.Srid))
}
if i != len(tableInfo.Cols())-1 {
needAddComma = true
}
Expand Down
4 changes: 4 additions & 0 deletions parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ const (
ColumnOptionColumnFormat
ColumnOptionStorage
ColumnOptionAutoRandom
ColumnOptionSrid
)

var (
Expand Down Expand Up @@ -549,6 +550,7 @@ type ColumnOption struct {
// Name is only used for Check Constraint name.
ConstraintName string
PrimaryKeyTp model.PrimaryKeyType
Srid uint32
}

// Restore implements Node interface.
Expand Down Expand Up @@ -649,6 +651,8 @@ func (n *ColumnOption) Restore(ctx *format.RestoreCtx) error {
}
return nil
})
case ColumnOptionSrid:
ctx.WritePlainf("/*!80003 SRID %d", n.Srid)
default:
return errors.New("An error occurred while splicing ColumnOption")
}
Expand Down
1 change: 1 addition & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ var tokenMap = map[string]int{
"SQL_TSI_WEEK": sqlTsiWeek,
"SQL_TSI_YEAR": sqlTsiYear,
"SQL": sql,
"SRID": srid,
"SSL": ssl,
"STALENESS": staleness,
"START": start,
Expand Down
1 change: 1 addition & 0 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ type ColumnInfo struct {
// Version = 1: For OriginDefaultValue and DefaultValue of timestamp column will stores the default time in UTC time zone.
// This will fix bug in version 0. For compatibility with version 0, we add version field in column info struct.
Version uint64 `json:"version"`
Srid uint32 `json:"srid"`
}

// Clone clones ColumnInfo.
Expand Down
6 changes: 6 additions & 0 deletions parser/mysql/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const (
OnUpdateNowFlag uint = 1 << 13 /* Field is set to NOW on UPDATE */
PartKeyFlag uint = 1 << 14 /* Intern: Part of some keys */
NumFlag uint = 1 << 15 /* Field is a num (for clients) */
SridFlag uint = 1 << 16 /* Field has a SRID */

GroupFlag uint = 1 << 15 /* Internal: Group field */
UniqueFlag uint = 1 << 16 /* Internal: Used by sql_yacc */
Expand Down Expand Up @@ -162,3 +163,8 @@ func HasPreventNullInsertFlag(flag uint) bool {
func HasEnumSetAsIntFlag(flag uint) bool {
return (flag & EnumSetAsIntFlag) > 0
}

// HasSridFlag checks if SridFlag is set.
func HasSridFlag(flag uint) bool {
return (flag & SridFlag) > 0
}
Loading

0 comments on commit e2c7f4c

Please sign in to comment.