appendEncodedText encodes item in text format as required by COPY and appends to buf
(buf []byte, x any)
| 138 | // appendEncodedText encodes item in text format as required by COPY |
| 139 | // and appends to buf |
| 140 | func appendEncodedText(buf []byte, x any) ([]byte, error) { |
| 141 | switch v := x.(type) { |
| 142 | case int64: |
| 143 | return strconv.AppendInt(buf, v, 10), nil |
| 144 | case float64: |
| 145 | return strconv.AppendFloat(buf, v, 'f', -1, 64), nil |
| 146 | case []byte: |
| 147 | encodedBytea := encodeBytea(v) |
| 148 | return appendEscapedText(buf, string(encodedBytea)), nil |
| 149 | case string: |
| 150 | return appendEscapedText(buf, v), nil |
| 151 | case bool: |
| 152 | return strconv.AppendBool(buf, v), nil |
| 153 | case time.Time: |
| 154 | return append(buf, formatTS(v)...), nil |
| 155 | case nil: |
| 156 | return append(buf, `\N`...), nil |
| 157 | default: |
| 158 | return nil, fmt.Errorf("pq: encode: unknown type for %T", v) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | func appendEscapedText(buf []byte, text string) []byte { |
| 163 | escapeNeeded := false |
searching dependent graphs…