Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,11 +1241,7 @@ type ColumnType struct {
Type string

// Generic field options.
NotNull bool
Autoincrement bool
Default Expr
OnUpdate Expr
Comment *Literal
Options *ColumnTypeOptions

// Numeric field options
Length *Literal
Expand All @@ -1259,6 +1255,15 @@ type ColumnType struct {

// Enum values
EnumValues []string
}

// ColumnTypeOptions are generic field options for a column type
type ColumnTypeOptions struct {
NotNull bool
Autoincrement bool
Default Expr
OnUpdate Expr
Comment *Literal

// Key specification
KeyOpt ColumnKeyOption
Expand Down Expand Up @@ -2220,37 +2225,37 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
if ct.Collate != "" {
opts = append(opts, keywordStrings[COLLATE], ct.Collate)
}
if ct.NotNull {
if ct.Options.NotNull {
opts = append(opts, keywordStrings[NOT], keywordStrings[NULL])
}
if ct.Default != nil {
opts = append(opts, keywordStrings[DEFAULT], String(ct.Default))
if ct.Options.Default != nil {
opts = append(opts, keywordStrings[DEFAULT], String(ct.Options.Default))
}
if ct.OnUpdate != nil {
opts = append(opts, keywordStrings[ON], keywordStrings[UPDATE], String(ct.OnUpdate))
if ct.Options.OnUpdate != nil {
opts = append(opts, keywordStrings[ON], keywordStrings[UPDATE], String(ct.Options.OnUpdate))
}
if ct.Autoincrement {
if ct.Options.Autoincrement {
opts = append(opts, keywordStrings[AUTO_INCREMENT])
}
if ct.Comment != nil {
opts = append(opts, keywordStrings[COMMENT_KEYWORD], String(ct.Comment))
if ct.Options.Comment != nil {
opts = append(opts, keywordStrings[COMMENT_KEYWORD], String(ct.Options.Comment))
}
if ct.KeyOpt == colKeyPrimary {
if ct.Options.KeyOpt == colKeyPrimary {
opts = append(opts, keywordStrings[PRIMARY], keywordStrings[KEY])
}
if ct.KeyOpt == colKeyUnique {
if ct.Options.KeyOpt == colKeyUnique {
opts = append(opts, keywordStrings[UNIQUE])
}
if ct.KeyOpt == colKeyUniqueKey {
if ct.Options.KeyOpt == colKeyUniqueKey {
opts = append(opts, keywordStrings[UNIQUE], keywordStrings[KEY])
}
if ct.KeyOpt == colKeySpatialKey {
if ct.Options.KeyOpt == colKeySpatialKey {
opts = append(opts, keywordStrings[SPATIAL], keywordStrings[KEY])
}
if ct.KeyOpt == colKeyFulltextKey {
if ct.Options.KeyOpt == colKeyFulltextKey {
opts = append(opts, keywordStrings[FULLTEXT], keywordStrings[KEY])
}
if ct.KeyOpt == colKey {
if ct.Options.KeyOpt == colKey {
opts = append(opts, keywordStrings[KEY])
}

Expand Down
36 changes: 24 additions & 12 deletions go/vt/sqlparser/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,9 @@ var (
}, {
input: "alter table a drop id",
output: "alter table a drop column id",
}, {
input: "ALTER TABLE `product115s` CHANGE `part_number` `part_number` varchar(255) DEFAULT '0' NOT NULL",
output: "alter table product115s change column part_number part_number varchar(255) not null default '0'",
}, {
input: "alter database character set geostd8",
}, {
Expand Down Expand Up @@ -1118,6 +1121,12 @@ var (
}, {
input: "create table a (b1 bool NOT NULL PRIMARY KEY, b2 boolean not null, KEY b2_idx(b))",
output: "create table a (\n\tb1 bool not null primary key,\n\tb2 boolean not null,\n\tKEY b2_idx (b)\n)",
}, {
input: "CREATE TABLE pkai (id INT PRIMARY KEY AUTO_INCREMENT);",
output: "create table pkai (\n\tid INT auto_increment primary key\n)",
}, {
input: "CREATE TABLE aipk (id INT AUTO_INCREMENT PRIMARY KEY)",
output: "create table aipk (\n\tid INT auto_increment primary key\n)",
}, {
input: "alter vschema create vindex hash_vdx using hash",
}, {
Expand Down
15 changes: 0 additions & 15 deletions go/vt/sqlparser/rewriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading