Remove rune to text conversion
Because rune is an alias for int32 this caused some very surprising results. e.g. inserting int32(65) into text would insert "A" instead of "65".
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type TextScanner interface {
|
||||
@@ -98,8 +97,6 @@ func (TextCodec) PlanEncode(m *Map, oid uint32, format int16, value any) EncodeP
|
||||
return encodePlanTextCodecString{}
|
||||
case []byte:
|
||||
return encodePlanTextCodecByteSlice{}
|
||||
case rune:
|
||||
return encodePlanTextCodecRune{}
|
||||
case TextValuer:
|
||||
return encodePlanTextCodecTextValuer{}
|
||||
}
|
||||
@@ -124,14 +121,6 @@ func (encodePlanTextCodecByteSlice) Encode(value any, buf []byte) (newBuf []byte
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
type encodePlanTextCodecRune struct{}
|
||||
|
||||
func (encodePlanTextCodecRune) Encode(value any, buf []byte) (newBuf []byte, err error) {
|
||||
r := value.(rune)
|
||||
buf = append(buf, string(r)...)
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
type encodePlanTextCodecStringer struct{}
|
||||
|
||||
func (encodePlanTextCodecStringer) Encode(value any, buf []byte) (newBuf []byte, err error) {
|
||||
@@ -169,8 +158,6 @@ func (TextCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
|
||||
return scanPlanAnyToByteScanner{}
|
||||
case TextScanner:
|
||||
return scanPlanTextAnyToTextScanner{}
|
||||
case *rune:
|
||||
return scanPlanTextAnyToRune{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,24 +210,6 @@ func (scanPlanAnyToByteScanner) Scan(src []byte, dst any) error {
|
||||
return p.ScanBytes(src)
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToRune struct{}
|
||||
|
||||
func (scanPlanTextAnyToRune) Scan(src []byte, dst any) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
r, size := utf8.DecodeRune(src)
|
||||
if size != len(src) {
|
||||
return fmt.Errorf("cannot scan %v into %T: more than one rune received", src, dst)
|
||||
}
|
||||
|
||||
p := (dst).(*rune)
|
||||
*p = r
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToTextScanner struct{}
|
||||
|
||||
func (scanPlanTextAnyToTextScanner) Scan(src []byte, dst any) error {
|
||||
|
||||
Reference in New Issue
Block a user