From 5db484908cf74895bb9e03414d1ba022a24e11bd Mon Sep 17 00:00:00 2001 From: Sebastiaan Mannem Date: Sun, 23 Aug 2020 00:21:46 +0200 Subject: [PATCH] Changing SendBytesWithResults to ReceiveResults (that only does the reading). --- pgconn.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/pgconn.go b/pgconn.go index decdc03d..e2ab5c13 100644 --- a/pgconn.go +++ b/pgconn.go @@ -904,14 +904,12 @@ func (pgConn *PgConn) Exec(ctx context.Context, sql string) *MultiResultReader { return multiResult } -// SendBytesWithResults sends buf to the PostgreSQL server. It must only be used when the connection is not busy. e.g. It is as -// error to call SendBytes while reading the result of a query. +// ReceiveResults reads the result that might be returned by Postgres after a SendBytes +// (e.a. after sending a CopyDone in a copy-both situation). // // This is a very low level method that requires deep understanding of the PostgreSQL wire protocol to use correctly. // See https://www.postgresql.org/docs/current/protocol.html. -// -// So far this only seems required with CopyDone handling. -func (pgConn *PgConn) SendBytesWithResults(ctx context.Context, buf []byte) *MultiResultReader { +func (pgConn *PgConn) ReceiveResults(ctx context.Context) *MultiResultReader { if err := pgConn.lock(); err != nil { return &MultiResultReader{ closed: true, @@ -936,16 +934,6 @@ func (pgConn *PgConn) SendBytesWithResults(ctx context.Context, buf []byte) *Mul pgConn.contextWatcher.Watch(ctx) } - n, err := pgConn.conn.Write(buf) - if err != nil { - pgConn.asyncClose() - pgConn.contextWatcher.Unwatch() - multiResult.closed = true - multiResult.err = &writeError{err: err, safeToRetry: n == 0} - pgConn.unlock() - return multiResult - } - return multiResult }