MCPcopy Create free account
hub / github.com/dolthub/doltgresql / extendFormatCodes

Function extendFormatCodes

server/doltgres_handler.go:477–496  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
477func 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
498func schemaToFieldDescriptions(ctx *sql.Context, s sql.Schema, formatCodes []int16) ([]pgproto3.FieldDescription, error) {
499 var err error

Callers 4

convertBindParametersMethod · 0.85
rowToBytesFunction · 0.85
handleBindMethod · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected