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)
| 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. |
| 56 | func (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. |
| 91 | func (eqb *ExtendedQueryBuilder) appendResultFormat(format int16) { |
no test coverage detected