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

Method appendParam

extended_query_builder.go:56–88  ·  view source on GitHub ↗

appendParam appends a parameter to the query. format may be -1 to automatically choose the format. If arg is nil it must be an untyped nil.

(m *pgtype.Map, oid uint32, format int16, arg any)

Source from the content-addressed store, hash-verified

54// appendParam appends a parameter to the query. format may be -1 to automatically choose the format. If arg is nil it
55// must be an untyped nil.
56func (eqb *ExtendedQueryBuilder) appendParam(m *pgtype.Map, oid uint32, format int16, arg any) error {
57 if format == -1 {
58 preferredFormat := eqb.chooseParameterFormatCode(m, oid, arg)
59 preferredErr := eqb.appendParam(m, oid, preferredFormat, arg)
60 if preferredErr == nil {
61 return nil
62 }
63
64 var otherFormat int16
65 if preferredFormat == TextFormatCode {
66 otherFormat = BinaryFormatCode
67 } else {
68 otherFormat = TextFormatCode
69 }
70
71 otherErr := eqb.appendParam(m, oid, otherFormat, arg)
72 if otherErr == nil {
73 return nil
74 }
75
76 return preferredErr // return the error from the preferred format
77 }
78
79 v, err := eqb.encodeExtendedParamValue(m, oid, format, arg)
80 if err != nil {
81 return err
82 }
83
84 eqb.ParamFormats = append(eqb.ParamFormats, format)
85 eqb.ParamValues = append(eqb.ParamValues, v)
86
87 return nil
88}
89
90// appendResultFormat appends a result format to the query.
91func (eqb *ExtendedQueryBuilder) appendResultFormat(format int16) {

Callers 1

BuildMethod · 0.95

Calls 2

Tested by

no test coverage detected