Skip to content

Commit 152a18a

Browse files
authored
Merge pull request #3065 from dolthub/Elian/issue9423
Added ErrInvalidColumnSpecifier error message Added enum type validation in validateAutoIncrementModify and validateAutoIncrementAdd Enabled previously skipped test case for enum auto_increment validation
2 parents 984abdb + 4bae40b commit 152a18a

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

enginetest/queries/script_queries.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9000,13 +9000,30 @@ where
90009000
},
90019001
},
90029002
{
9003-
Skip: true,
9004-
Name: "enums with auto increment",
9005-
Dialect: "mysql",
9006-
SetUpScript: []string{},
9003+
Name: "enums with auto increment",
9004+
Dialect: "mysql",
9005+
SetUpScript: []string{
9006+
"CREATE TABLE t (e enum('a', 'b', 'c') PRIMARY KEY)",
9007+
},
90079008
Assertions: []ScriptTestAssertion{
90089009
{
9009-
Query: "create table t (e enum('a', 'b', 'c') primary key auto_increment);",
9010+
Query: "CREATE TABLE t2 (e enum('a', 'b', 'c') PRIMARY KEY AUTO_INCREMENT)",
9011+
ExpectedErrStr: "Incorrect column specifier for column 'e'",
9012+
},
9013+
{
9014+
Query: "ALTER TABLE t MODIFY e enum('a', 'b', 'c') AUTO_INCREMENT",
9015+
ExpectedErrStr: "Incorrect column specifier for column 'e'",
9016+
},
9017+
{
9018+
Query: "ALTER TABLE t MODIFY COLUMN e enum('a', 'b', 'c') AUTO_INCREMENT",
9019+
ExpectedErrStr: "Incorrect column specifier for column 'e'",
9020+
},
9021+
{
9022+
Query: "ALTER TABLE t CHANGE e e enum('a', 'b', 'c') AUTO_INCREMENT",
9023+
ExpectedErrStr: "Incorrect column specifier for column 'e'",
9024+
},
9025+
{
9026+
Query: "ALTER TABLE t CHANGE COLUMN e e enum('a', 'b', 'c') AUTO_INCREMENT",
90109027
ExpectedErrStr: "Incorrect column specifier for column 'e'",
90119028
},
90129029
},

sql/analyzer/validate_create_table.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ func validateAutoIncrementModify(schema sql.Schema, keyedColumns map[string]bool
791791
seen := false
792792
for _, col := range schema {
793793
if col.AutoIncrement {
794+
// Check if column type is valid for auto_increment
795+
if types.IsEnum(col.Type) {
796+
return sql.ErrInvalidColumnSpecifier.New(col.Name)
797+
}
794798
// keyedColumns == nil means they are trying to add auto_increment column
795799
if !col.PrimaryKey && !keyedColumns[col.Name] {
796800
// AUTO_INCREMENT col must be a key
@@ -815,6 +819,10 @@ func validateAutoIncrementAdd(schema sql.Schema, keyColumns map[string]bool) err
815819
for _, col := range schema {
816820
if col.AutoIncrement {
817821
{
822+
// Check if column type is valid for auto_increment
823+
if types.IsEnum(col.Type) {
824+
return sql.ErrInvalidColumnSpecifier.New(col.Name)
825+
}
818826
if !col.PrimaryKey && !keyColumns[col.Name] {
819827
// AUTO_INCREMENT col must be a key
820828
return sql.ErrInvalidAutoIncCols.New()

sql/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ var (
672672
// ErrInvalidAutoIncCols is returned when an auto_increment column cannot be applied
673673
ErrInvalidAutoIncCols = errors.NewKind("there can be only one auto_increment column and it must be defined as a key")
674674

675+
// ErrInvalidColumnSpecifier is returned when an invalid column specifier is used
676+
ErrInvalidColumnSpecifier = errors.NewKind("Incorrect column specifier for column '%s'")
677+
675678
// ErrUnknownConstraintDefinition is returned when an unknown constraint type is used
676679
ErrUnknownConstraintDefinition = errors.NewKind("unknown constraint definition: %s, %T")
677680

0 commit comments

Comments
 (0)