@@ -509,7 +509,7 @@ func convertToLongTextString(ctx context.Context, val interface{}) (string, erro
509
509
}
510
510
511
511
// convertEnumToString converts an enum value to its string representation
512
- func convertEnumToString (ctx context.Context , val interface {}, enumType sql. EnumType ) (string , error ) {
512
+ func convertEnumToString (ctx context.Context , val interface {}, enumType EnumType ) (string , error ) {
513
513
if enumVal , ok := val .(uint16 ); ok {
514
514
if enumStr , exists := enumType .At (int (enumVal )); exists {
515
515
return enumStr , nil
@@ -519,6 +519,14 @@ func convertEnumToString(ctx context.Context, val interface{}, enumType sql.Enum
519
519
return convertToLongTextString (ctx , val )
520
520
}
521
521
522
+ // convertSetToString converts a set value to its string representation
523
+ func convertSetToString (ctx context.Context , val interface {}, setType SetType ) (string , error ) {
524
+ if setVal , ok := val .(uint64 ); ok {
525
+ return setType .BitsToString (setVal )
526
+ }
527
+ return convertToLongTextString (ctx , val )
528
+ }
529
+
522
530
// ConvertToCollatedString returns the given interface as a string, along with its collation. If the Type possess a
523
531
// collation, then that collation is returned. If the Type does not possess a collation (such as an integer), then the
524
532
// value is converted to a string and the default collation is used. If the value is already a string then no additional
@@ -539,28 +547,27 @@ func ConvertToCollatedString(ctx context.Context, val interface{}, typ sql.Type)
539
547
content = strVal
540
548
} else if byteVal , ok := val .([]byte ); ok {
541
549
content = encodings .BytesToString (byteVal )
542
- } else if enumType , ok := typ .(sql.EnumType ); ok {
543
- // Handle enum types in string context - return the string value, not the index
544
- content , err = convertEnumToString (ctx , val , enumType )
545
- if err != nil {
546
- return "" , sql .Collation_Unspecified , err
547
- }
548
550
} else {
549
- content , err = convertToLongTextString (ctx , val )
550
- if err != nil {
551
- return "" , sql .Collation_Unspecified , err
551
+ switch typ := typ .(type ) {
552
+ case EnumType :
553
+ content , err = convertEnumToString (ctx , val , typ )
554
+ if err != nil {
555
+ return "" , sql .Collation_Unspecified , err
556
+ }
557
+ case SetType :
558
+ content , err = convertSetToString (ctx , val , typ )
559
+ if err != nil {
560
+ return "" , sql .Collation_Unspecified , err
561
+ }
562
+ default :
563
+ content , err = convertToLongTextString (ctx , val )
564
+ if err != nil {
565
+ return "" , sql .Collation_Unspecified , err
566
+ }
552
567
}
553
568
}
554
569
} else {
555
570
collation = sql .Collation_Default
556
- // Handle enum types in string context even without collation
557
- if enumType , ok := typ .(sql.EnumType ); ok {
558
- content , err = convertEnumToString (ctx , val , enumType )
559
- if err != nil {
560
- return "" , sql .Collation_Unspecified , err
561
- }
562
- return content , collation , nil
563
- }
564
571
content , err = convertToLongTextString (ctx , val )
565
572
if err != nil {
566
573
return "" , sql .Collation_Unspecified , err
0 commit comments