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

Method Exec

pgconn/pgconn.go:1197–1234  ·  view source on GitHub ↗

Exec executes SQL via the PostgreSQL simple query protocol. SQL may contain multiple queries. Execution is implicitly wrapped in a transaction unless a transaction is already in progress or SQL contains transaction control statements. Prefer [PgConn.ExecParams] unless executing arbitrary SQL that m

(ctx context.Context, sql string)

Source from the content-addressed store, hash-verified

1195//
1196// Prefer [PgConn.ExecParams] unless executing arbitrary SQL that may contain multiple queries.
1197func (pgConn *PgConn) Exec(ctx context.Context, sql string) *MultiResultReader {
1198 if err := pgConn.lock(); err != nil {
1199 return &MultiResultReader{
1200 closed: true,
1201 err: err,
1202 }
1203 }
1204
1205 pgConn.multiResultReader = MultiResultReader{
1206 pgConn: pgConn,
1207 ctx: ctx,
1208 }
1209 multiResult := &pgConn.multiResultReader
1210 if ctx != context.Background() {
1211 select {
1212 case <-ctx.Done():
1213 multiResult.closed = true
1214 multiResult.err = newContextAlreadyDoneError(ctx)
1215 pgConn.unlock()
1216 return multiResult
1217 default:
1218 }
1219 pgConn.contextWatcher.Watch(ctx)
1220 }
1221
1222 pgConn.frontend.SendQuery(&pgproto3.Query{String: sql})
1223 err := pgConn.flushWithPotentialWriteReadDeadlock()
1224 if err != nil {
1225 pgConn.asyncClose()
1226 pgConn.contextWatcher.Unwatch()
1227 multiResult.closed = true
1228 multiResult.err = err
1229 pgConn.unlock()
1230 return multiResult
1231 }
1232
1233 return multiResult
1234}
1235
1236// ExecParams executes a command via the PostgreSQL extended query protocol.
1237//

Callers 1

PingMethod · 0.95

Calls 8

lockMethod · 0.95
unlockMethod · 0.95
asyncCloseMethod · 0.95
WatchMethod · 0.80
SendQueryMethod · 0.80
UnwatchMethod · 0.80

Tested by

no test coverage detected