Build sets ParamValues, ParamFormats, and ResultFormats for use with *PgConn.ExecParams or *PgConn.ExecPrepared. If sd is nil then QueryExecModeExec behavior will be used.
(m *pgtype.Map, sd *pgconn.StatementDescription, args []any)
| 19 | // Build sets ParamValues, ParamFormats, and ResultFormats for use with *PgConn.ExecParams or *PgConn.ExecPrepared. If |
| 20 | // sd is nil then QueryExecModeExec behavior will be used. |
| 21 | func (eqb *ExtendedQueryBuilder) Build(m *pgtype.Map, sd *pgconn.StatementDescription, args []any) error { |
| 22 | eqb.reset() |
| 23 | |
| 24 | if sd == nil { |
| 25 | for i := range args { |
| 26 | err := eqb.appendParam(m, 0, pgtype.TextFormatCode, args[i]) |
| 27 | if err != nil { |
| 28 | err = fmt.Errorf("failed to encode args[%d]: %w", i, err) |
| 29 | return err |
| 30 | } |
| 31 | } |
| 32 | return nil |
| 33 | } |
| 34 | |
| 35 | if len(sd.ParamOIDs) != len(args) { |
| 36 | return fmt.Errorf("mismatched param and argument count") |
| 37 | } |
| 38 | |
| 39 | for i := range args { |
| 40 | err := eqb.appendParam(m, sd.ParamOIDs[i], -1, args[i]) |
| 41 | if err != nil { |
| 42 | err = fmt.Errorf("failed to encode args[%d]: %w", i, err) |
| 43 | return err |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | for i := range sd.Fields { |
| 48 | eqb.appendResultFormat(m.FormatCodeForOID(sd.Fields[i].DataTypeOID)) |
| 49 | } |
| 50 | |
| 51 | return nil |
| 52 | } |
| 53 | |
| 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. |