MCPcopy Create free account
hub / github.com/apecloud/myduckserver / encodeColumnData

Function encodeColumnData

pgserver/logrepl/replication.go:925–957  ·  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

923// encodeColumnData encodes the given data using the given data type OID and returns the result as a string to be
924// used in an INSERT or other DML query.
925func encodeColumnData(mi *pgtype.Map, data interface{}, dataType uint32) (string, error) {
926 var value string
927 if dt, ok := mi.TypeForOID(dataType); ok {
928 e := dt.Codec.PlanEncode(mi, dataType, pgtype.TextFormatCode, data)
929 if e != nil {
930 encoded, err := e.Encode(data, nil)
931 if err != nil {
932 return "", err
933 }
934 value = string(encoded)
935 } else {
936 // no encoder for this type, use the string representation
937 value = fmt.Sprintf("%v", data)
938 }
939 } else {
940 value = fmt.Sprintf("%v", data)
941 }
942
943 // Some types need additional quoting after encoding
944 switch data := data.(type) {
945 case string, time.Time, pgtype.Time, bool:
946 return fmt.Sprintf("'%s'", value), nil
947 case [16]byte:
948 // TODO: should we actually register an encoder for this type?
949 bytes, err := mi.Encode(pgtype.UUIDOID, pgtype.TextFormatCode, data, nil)
950 if err != nil {
951 return "", err
952 }
953 return `'` + string(bytes) + `'`, nil
954 default:
955 return value, nil
956 }
957}
958
959// mayExtendBatchTxn checks if we should extend the current batch transaction
960func (r *LogicalReplicator) mayExtendBatchTxn(state *replicationState) (bool, delta.FlushReason) {

Callers

nothing calls this directly

Calls 1

EncodeMethod · 0.45

Tested by

no test coverage detected