@@ -9029,23 +9029,62 @@ where
90299029 },
90309030 },
90319031 {
9032- // This is with STRICT_TRANS_TABLES or STRICT_ALL_TABLES in sql_mode
9032+ // Test enum validation with zero values in strict mode - GitHub issue #9425
90339033 Skip : false ,
9034- Name : "enums with zero" ,
9034+ Name : "enums with zero strict mode " ,
90359035 Dialect : "mysql" ,
90369036 SetUpScript : []string {
9037+ "set sql_mode = 'STRICT_TRANS_TABLES';" ,
90379038 "create table t (e enum('a', 'b', 'c'));" ,
9039+ "create table t_empty (e enum('', 'a', 'b'));" , // enum with explicit empty string
90389040 },
90399041 Assertions : []ScriptTestAssertion {
90409042 {
90419043 Query : "insert into t values (0);" ,
9042- // Fixed: should now be truncated error in strict mode
9044+ ExpectedErrStr : "Data truncated for column 'e' at row 1" ,
9045+ },
9046+ {
9047+ Query : "insert into t values (1), (0);" ,
9048+ ExpectedErrStr : "Data truncated for column 'e' at row 2" ,
9049+ },
9050+ {
9051+ Query : "insert into t values (0), (0);" ,
90439052 ExpectedErrStr : "Data truncated for column 'e' at row 1" ,
90449053 },
90459054 {
90469055 Query : "create table tt (e enum('a', 'b', 'c') default 0)" ,
90479056 ExpectedErr : sql .ErrInvalidColumnDefaultValue ,
90489057 },
9058+ {
9059+ // Test enum with explicit empty string - should allow 0
9060+ Query : "insert into t_empty values (0);" ,
9061+ Expected : []sql.Row {{}},
9062+ },
9063+ {
9064+ Query : "select e from t_empty;" ,
9065+ Expected : []sql.Row {{"" }},
9066+ },
9067+ },
9068+ },
9069+ {
9070+ // Test enum zero behavior in non-strict mode for comparison
9071+ Skip : false ,
9072+ Name : "enums with zero non-strict mode" ,
9073+ Dialect : "mysql" ,
9074+ SetUpScript : []string {
9075+ "set sql_mode = '';" , // non-strict mode
9076+ "create table t (e enum('a', 'b', 'c'));" ,
9077+ },
9078+ Assertions : []ScriptTestAssertion {
9079+ {
9080+ // In non-strict mode, 0 should be allowed and convert to empty string
9081+ Query : "insert into t values (0);" ,
9082+ Expected : []sql.Row {{}},
9083+ },
9084+ {
9085+ Query : "select e from t;" ,
9086+ Expected : []sql.Row {{"" }},
9087+ },
90499088 },
90509089 },
90519090 {
0 commit comments