@@ -185,18 +185,22 @@ func (h *Hex) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
185185 }
186186
187187 switch val := arg .(type ) {
188- case string :
188+ case string , sql.StringWrapper :
189+ s , _ , err := sql .Unwrap [string ](ctx , val )
190+ if err != nil {
191+ return nil , err
192+ }
189193 childType := h .Child .Type ()
190194 if types .IsTextOnly (childType ) {
191195 // For string types we need to re-encode the internal string so that we get the correct hex output
192196 encoder := childType .(sql.StringType ).Collation ().CharacterSet ().Encoder ()
193- encodedBytes , ok := encoder .Encode (encodings .StringToBytes (val ))
197+ encodedBytes , ok := encoder .Encode (encodings .StringToBytes (s ))
194198 if ! ok {
195199 return nil , fmt .Errorf ("unable to re-encode string for HEX function" )
196200 }
197201 return hexForString (encodings .BytesToString (encodedBytes )), nil
198202 } else {
199- return hexForString (val ), nil
203+ return hexForString (s ), nil
200204 }
201205
202206 case uint8 , uint16 , uint32 , uint , int , int8 , int16 , int32 , int64 :
@@ -244,8 +248,12 @@ func (h *Hex) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
244248
245249 return hexForString (s ), nil
246250
247- case []byte :
248- return hexForString (string (val )), nil
251+ case []byte , sql.BytesWrapper :
252+ b , _ , err := sql .Unwrap [[]byte ](ctx , val )
253+ if err != nil {
254+ return nil , err
255+ }
256+ return hexForString (string (b )), nil
249257
250258 case types.GeometryValue :
251259 return hexForString (string (val .Serialize ())), nil
0 commit comments