| 1943 | } |
| 1944 | |
| 1945 | func 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 |