@@ -107,20 +107,6 @@ func CreateEnumType(values []string, collation sql.CollationID) (sql.EnumType, e
107107 }, nil
108108}
109109
110- // isInsertContext determines if we're in an insert operation context where column name and row information
111- // are available for error reporting, versus other contexts like CREATE TABLE default validation.
112- func isInsertContext (ctx * sql.Context ) bool {
113- // Check if we're in an insert operation by looking for insert-specific context information
114- // During insert operations, the context typically has access to row iteration state
115- if ctx == nil {
116- return false
117- }
118-
119- // Check the query string for INSERT keywords
120- query := strings .ToUpper (strings .TrimSpace (ctx .Query ()))
121- return strings .HasPrefix (query , "INSERT" ) || strings .HasPrefix (query , "REPLACE" ) || strings .Contains (query , "ON DUPLICATE KEY UPDATE" )
122- }
123-
124110// MustCreateEnumType is the same as CreateEnumType except it panics on errors.
125111func MustCreateEnumType (values []string , collation sql.CollationID ) sql.EnumType {
126112 et , err := CreateEnumType (values , collation )
@@ -186,14 +172,7 @@ func (t EnumType) Convert(ctx context.Context, v interface{}) (interface{}, sql.
186172 // In strict mode, 0 values are not allowed for enums unless empty string is explicitly defined
187173 // Check if empty string is an actual enum value (not just the default index 0)
188174 if t .IndexOf ("" ) == - 1 {
189- // For insert operations, return the specific error that will be filled in with column/row info
190- // For other operations (e.g., CREATE TABLE default validation), return the generic error
191- // Check if this is an insert context by looking for a wrapped insert error or row count info
192- if isInsertContext (sqlCtx ) {
193- return nil , sql .InRange , ErrDataTruncatedForColumn .New ("" , 0 )
194- }
195- // For default value validation and other contexts, return the generic error
196- return nil , sql .InRange , ErrConvertingToEnum .New (v )
175+ return nil , sql .InRange , ErrDataTruncatedForColumn .New ("" )
197176 }
198177 // Empty string is a defined enum value, allow it
199178 return uint16 (0 ), sql .InRange , nil
@@ -344,10 +323,6 @@ func (t EnumType) Collation() sql.CollationID {
344323
345324// IndexOf implements EnumType interface.
346325func (t EnumType ) IndexOf (v string ) int {
347- // Empty string always maps to index 0 for INSERT IGNORE compatibility
348- if v == "" {
349- return 0
350- }
351326 if idx , ok := t .valToIdx [v ]; ok {
352327 return idx
353328 }
0 commit comments