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

Method Build

extended_query_builder.go:21–52  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
21func (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.

Callers 7

execParamsMethod · 0.80
execPreparedMethod · 0.80
execSQLParamsMethod · 0.80
QueryMethod · 0.80

Calls 4

resetMethod · 0.95
appendParamMethod · 0.95
appendResultFormatMethod · 0.95
FormatCodeForOIDMethod · 0.80