MCPcopy
hub / github.com/jackc/pgx / newEncodeError

Function newEncodeError

pgtype/pgtype.go:1945–1964  ·  view source on GitHub ↗
(value any, m *Map, oid uint32, formatCode int16, err error)

Source from the content-addressed store, hash-verified

1943}
1944
1945func newEncodeError(value any, m *Map, oid uint32, formatCode int16, err error) error {
1946 var format string
1947 switch formatCode {
1948 case TextFormatCode:
1949 format = "text"
1950 case BinaryFormatCode:
1951 format = "binary"
1952 default:
1953 format = fmt.Sprintf("unknown (%d)", formatCode)
1954 }
1955
1956 var dataTypeName string
1957 if t, ok := m.TypeForOID(oid); ok {
1958 dataTypeName = t.Name
1959 } else {
1960 dataTypeName = "unknown type"
1961 }
1962
1963 return fmt.Errorf("unable to encode %#v into %s format for %s (OID %d): %w", value, format, dataTypeName, oid, err)
1964}
1965
1966// Encode appends the encoded bytes of value to buf. If value is the SQL value NULL then append nothing and return
1967// (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data

Callers 1

EncodeMethod · 0.85

Calls 1

TypeForOIDMethod · 0.80

Tested by

no test coverage detected