extendFormatCodes ensures that the given format codes match the expected field length by extending the short-form variant (or returning the full-form as-is).
(fieldLength int, formatCodes []int16)
| 475 | // extendFormatCodes ensures that the given format codes match the expected field length by extending the short-form |
| 476 | // variant (or returning the full-form as-is). |
| 477 | func extendFormatCodes(fieldLength int, formatCodes []int16) ([]int16, error) { |
| 478 | if !ForceTextWireFormat && len(formatCodes) > 0 { |
| 479 | // It's valid to send just one format code that should be used by all values, so we extend the slice in that case |
| 480 | if len(formatCodes) < fieldLength { |
| 481 | if len(formatCodes) > 1 { |
| 482 | return nil, errors.Errorf(`format codes have length "%d" but fields have length "%d"`, len(formatCodes), fieldLength) |
| 483 | } |
| 484 | newFormatCodes := make([]int16, fieldLength) |
| 485 | for i := range newFormatCodes { |
| 486 | newFormatCodes[i] = formatCodes[0] |
| 487 | } |
| 488 | return newFormatCodes, nil |
| 489 | } else { |
| 490 | return formatCodes, nil |
| 491 | } |
| 492 | } else { |
| 493 | // This defaults to zero, which means all format codes represent the "text" option |
| 494 | return make([]int16, fieldLength), nil |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | func schemaToFieldDescriptions(ctx *sql.Context, s sql.Schema, formatCodes []int16) ([]pgproto3.FieldDescription, error) { |
| 499 | var err error |
no test coverage detected