MCPcopy Create free account
hub / github.com/dolthub/doltgresql / encodeColumnData

Function encodeColumnData

server/logrepl/replication.go:816–845  ·  view source on GitHub ↗

encodeColumnData encodes the given data using the given data type OID and returns the result as a string to be used in an INSERT or other DML query.

(mi *pgtype.Map, data interface{}, dataType uint32)

Source from the content-addressed store, hash-verified

814// encodeColumnData encodes the given data using the given data type OID and returns the result as a string to be
815// used in an INSERT or other DML query.
816func encodeColumnData(mi *pgtype.Map, data interface{}, dataType uint32) (string, error) {
817 var value string
818 if dt, ok := mi.TypeForOID(dataType); ok {
819 e := dt.Codec.PlanEncode(mi, dataType, pgtype.TextFormatCode, data)
820 if e != nil {
821 encoded, err := e.Encode(data, nil)
822 if err != nil {
823 return "", err
824 }
825 value = string(encoded)
826 } else {
827 // no encoder for this type, use the string representation
828 value = fmt.Sprintf("%v", data)
829 }
830 } else {
831 value = fmt.Sprintf("%v", data)
832 }
833
834 // Some types need additional quoting after encoding
835 switch data := data.(type) {
836 case string, time.Time, pgtype.Time, bool:
837 return fmt.Sprintf("'%s'", value), nil
838 case [16]byte:
839 // TODO: should we actually register an encoder for this type?
840 uid := uuid.UUID(data)
841 return fmt.Sprintf("'%s'", uid.String()), nil
842 default:
843 return value, nil
844 }
845}

Callers 1

processMessageMethod · 0.85

Calls 3

UUIDTypeAlias · 0.92
StringMethod · 0.65
EncodeMethod · 0.45

Tested by

no test coverage detected