diff --git a/pgconn/pgconn.go b/pgconn/pgconn.go index be7d37ae..7cf3c91d 100644 --- a/pgconn/pgconn.go +++ b/pgconn/pgconn.go @@ -347,7 +347,7 @@ func (pgConn *PgConn) ParameterStatus(key string) string { } // CommandTag is the result of an Exec function -type CommandTag []byte +type CommandTag string // RowsAffected returns the number of rows affected. If the CommandTag was not // for a row affecting command (e.g. "CREATE TABLE") then it returns 0. @@ -361,10 +361,6 @@ func (ct CommandTag) RowsAffected() int64 { return n } -func (ct CommandTag) String() string { - return string(ct) -} - // preferContextOverNetTimeoutError returns ctx.Err() if ctx.Err() is present and err is a net.Error with Timeout() == // true. Otherwise returns err. func preferContextOverNetTimeoutError(ctx context.Context, err error) error { @@ -602,7 +598,7 @@ func (pgConn *PgConn) ExecParams(ctx context.Context, sql string, paramValues [] select { case <-ctx.Done(): - result.concludeCommand(nil, ctx.Err()) + result.concludeCommand("", ctx.Err()) result.closed = true return result case pgConn.controller <- result: @@ -628,7 +624,7 @@ func (pgConn *PgConn) ExecParams(ctx context.Context, sql string, paramValues [] pgConn.closed = true } - result.concludeCommand(nil, err) + result.concludeCommand("", err) result.cleanupContextDeadline() result.closed = true <-pgConn.controller @@ -658,7 +654,7 @@ func (pgConn *PgConn) ExecPrepared(ctx context.Context, stmtName string, paramVa select { case <-ctx.Done(): - result.concludeCommand(nil, ctx.Err()) + result.concludeCommand("", ctx.Err()) result.closed = true return result case pgConn.controller <- result: @@ -680,7 +676,7 @@ func (pgConn *PgConn) ExecPrepared(ctx context.Context, stmtName string, paramVa pgConn.closed = true } - result.concludeCommand(nil, err) + result.concludeCommand("", err) result.cleanupContextDeadline() result.closed = true <-pgConn.controller @@ -870,7 +866,7 @@ func (rr *ResultReader) Close() (CommandTag, error) { for !rr.commandConcluded { _, err := rr.receiveMessage() if err != nil { - return nil, rr.err + return "", rr.err } } @@ -878,7 +874,7 @@ func (rr *ResultReader) Close() (CommandTag, error) { for { msg, err := rr.receiveMessage() if err != nil { - return nil, rr.err + return "", rr.err } switch msg.(type) { @@ -901,7 +897,7 @@ func (rr *ResultReader) receiveMessage() (msg pgproto3.BackendMessage, err error } if err != nil { - rr.concludeCommand(nil, err) + rr.concludeCommand("", err) rr.cleanupContextDeadline() rr.closed = true if rr.multiResultReader == nil { @@ -921,7 +917,7 @@ func (rr *ResultReader) receiveMessage() (msg pgproto3.BackendMessage, err error case *pgproto3.CommandComplete: rr.concludeCommand(CommandTag(msg.CommandTag), nil) case *pgproto3.ErrorResponse: - rr.concludeCommand(nil, errorResponseToPgError(msg)) + rr.concludeCommand("", errorResponseToPgError(msg)) } return msg, nil diff --git a/pgconn/pgconn_test.go b/pgconn/pgconn_test.go index a524d18f..a63aee38 100644 --- a/pgconn/pgconn_test.go +++ b/pgconn/pgconn_test.go @@ -375,7 +375,7 @@ func TestConnExecParamsCanceled(t *testing.T) { } assert.Equal(t, 0, rowCount) commandTag, err := result.Close() - assert.Nil(t, commandTag) + assert.Equal(t, pgconn.CommandTag(""), commandTag) assert.Equal(t, context.DeadlineExceeded, err) ensureConnValid(t, pgConn) @@ -427,7 +427,7 @@ func TestConnExecPreparedCanceled(t *testing.T) { } assert.Equal(t, 0, rowCount) commandTag, err := result.Close() - assert.Nil(t, commandTag) + assert.Equal(t, pgconn.CommandTag(""), commandTag) assert.Equal(t, context.DeadlineExceeded, err) ensureConnValid(t, pgConn)