Skip to content

Commit 9922a91

Browse files
elianddbclaude
andcommitted
Enhance TypeAwareConversion to handle blob types for consistent SET/ENUM casting
- Extend TypeAwareConversion to handle IsBlobType in addition to IsTextOnly - Use TypeAwareConversion consistently for both CHAR and BINARY conversions - Remove direct ConvertToCollatedString call in binary conversion - Update function documentation to reflect blob type support - Simplify convertValue logic by using unified conversion approach This ensures SET/ENUM types are converted properly for all string and binary target types through a single, consistent code path. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 586248c commit 9922a91

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

sql/expression/convert.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ func convertValue(ctx *sql.Context, val interface{}, castTo string, originType s
293293
}
294294
switch strings.ToLower(castTo) {
295295
case ConvertToBinary:
296-
// For SET/ENUM types, convert to string first since TypeAwareConversion only handles text types
296+
// For SET/ENUM types, convert to string first for blob conversions
297297
if types.IsSet(originType) || types.IsEnum(originType) {
298-
val, _, _ = types.ConvertToCollatedString(ctx, val, originType)
298+
val, _ = types.TypeAwareConversion(ctx, val, originType, types.LongText)
299299
}
300300
b, _, err := types.LongBlob.Convert(ctx, val)
301301
if err != nil {
@@ -477,7 +477,6 @@ func createConvertedDecimalType(length, scale int, logErrors bool) sql.DecimalTy
477477
return types.InternalDecimalType
478478
}
479479

480-
481480
// convertHexBlobToDecimalForNumericContext converts byte array value to unsigned int value if originType is BLOB type.
482481
// This function is called when convertTo type is number type only. The hex literal values are parsed into blobs as
483482
// binary string as default, but for numeric context, the value should be a number.

0 commit comments

Comments
 (0)