From e78fd952963970ee2062f113ee8115b0ce54649c Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 5 Jan 2019 18:53:07 -0600 Subject: [PATCH] Fix switching CommandTag back to string --- batch.go | 10 +++++----- conn.go | 18 +++++++++--------- conn_pool.go | 4 ++-- copy_from.go | 16 ++++++++-------- copy_to.go | 14 +++++++------- pgmock/pgmock.go | 20 ++++++++++---------- tx.go | 4 ++-- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/batch.go b/batch.go index 11397c2e..5664b4cd 100644 --- a/batch.go +++ b/batch.go @@ -165,19 +165,19 @@ func (b *Batch) Send(ctx context.Context, txOptions *TxOptions) error { // query has been sent with Exec. func (b *Batch) ExecResults() (pgconn.CommandTag, error) { if b.err != nil { - return nil, b.err + return "", b.err } select { case <-b.ctx.Done(): b.die(b.ctx.Err()) - return nil, b.ctx.Err() + return "", b.ctx.Err() default: } if err := b.ensureCommandComplete(); err != nil { b.die(err) - return nil, err + return "", err } b.resultsRead++ @@ -187,7 +187,7 @@ func (b *Batch) ExecResults() (pgconn.CommandTag, error) { for { msg, err := b.conn.rxMsg() if err != nil { - return nil, err + return "", err } switch msg := msg.(type) { @@ -196,7 +196,7 @@ func (b *Batch) ExecResults() (pgconn.CommandTag, error) { return pgconn.CommandTag(msg.CommandTag), nil default: if err := b.conn.processContextFreeMsg(msg); err != nil { - return nil, err + return "", err } } } diff --git a/conn.go b/conn.go index e02f905f..e3ed21cd 100644 --- a/conn.go +++ b/conn.go @@ -1184,16 +1184,16 @@ func (c *Conn) Exec(ctx context.Context, sql string, arguments ...interface{}) ( c.lastStmtSent = false err := c.waitForPreviousCancelQuery(ctx) if err != nil { - return nil, err + return "", err } if err := c.lock(); err != nil { - return nil, err + return "", err } defer c.unlock() if err := c.ensureConnectionReadyForQuery(); err != nil { - return nil, err + return "", err } startTime := time.Now() @@ -1219,18 +1219,18 @@ func (c *Conn) exec(ctx context.Context, sql string, arguments ...interface{}) ( c.lastStmtSent = true result, err := c.pgConn.Exec(ctx, sql) if err != nil { - return nil, err + return "", err } return result.CommandTag, nil } else { psd, err := c.pgConn.Prepare(ctx, "", sql, nil) if err != nil { - return nil, err + return "", err } if len(psd.ParamOIDs) != len(arguments) { - return nil, errors.Errorf("expected %d arguments, got %d", len(psd.ParamOIDs), len(arguments)) + return "", errors.Errorf("expected %d arguments, got %d", len(psd.ParamOIDs), len(arguments)) } ps := &PreparedStatement{ @@ -1249,7 +1249,7 @@ func (c *Conn) exec(ctx context.Context, sql string, arguments ...interface{}) ( arguments, err = convertDriverValuers(arguments) if err != nil { - return nil, err + return "", err } paramFormats := make([]int16, len(arguments)) @@ -1258,7 +1258,7 @@ func (c *Conn) exec(ctx context.Context, sql string, arguments ...interface{}) ( paramFormats[i] = chooseParameterFormatCode(c.ConnInfo, ps.ParameterOIDs[i], arguments[i]) paramValues[i], err = newencodePreparedStatementArgument(c.ConnInfo, ps.ParameterOIDs[i], arguments[i]) if err != nil { - return nil, err + return "", err } } @@ -1271,7 +1271,7 @@ func (c *Conn) exec(ctx context.Context, sql string, arguments ...interface{}) ( c.lastStmtSent = true result, err := c.pgConn.ExecPrepared(ctx, psd.Name, paramValues, paramFormats, resultFormats) if err != nil { - return nil, err + return "", err } return result.CommandTag, nil diff --git a/conn_pool.go b/conn_pool.go index 9e6f83db..772d96cc 100644 --- a/conn_pool.go +++ b/conn_pool.go @@ -548,7 +548,7 @@ func (p *ConnPool) CopyFrom(tableName Identifier, columnNames []string, rowSrc C func (p *ConnPool) CopyFromReader(r io.Reader, sql string) (pgconn.CommandTag, error) { c, err := p.Acquire() if err != nil { - return nil, err + return "", err } defer p.Release(c) @@ -559,7 +559,7 @@ func (p *ConnPool) CopyFromReader(r io.Reader, sql string) (pgconn.CommandTag, e func (p *ConnPool) CopyToWriter(w io.Writer, sql string, args ...interface{}) (pgconn.CommandTag, error) { c, err := p.Acquire() if err != nil { - return nil, err + return "", err } defer p.Release(c) diff --git a/copy_from.go b/copy_from.go index 8904f419..3e7f4514 100644 --- a/copy_from.go +++ b/copy_from.go @@ -287,11 +287,11 @@ func (c *Conn) CopyFrom(tableName Identifier, columnNames []string, rowSrc CopyF // CopyFromReader uses the PostgreSQL textual format of the copy protocol func (c *Conn) CopyFromReader(r io.Reader, sql string) (pgconn.CommandTag, error) { if err := c.sendSimpleQuery(sql); err != nil { - return nil, err + return "", err } if err := c.readUntilCopyInResponse(); err != nil { - return nil, err + return "", err } buf := c.wbuf @@ -306,7 +306,7 @@ func (c *Conn) CopyFromReader(r io.Reader, sql string) (pgconn.CommandTag, error pgio.SetInt32(buf[sp:], int32(n+4)) if _, err := c.pgConn.Conn().Write(buf); err != nil { - return nil, err + return "", err } } @@ -315,25 +315,25 @@ func (c *Conn) CopyFromReader(r io.Reader, sql string) (pgconn.CommandTag, error buf = pgio.AppendInt32(buf, 4) if _, err := c.pgConn.Conn().Write(buf); err != nil { - return nil, err + return "", err } for { msg, err := c.rxMsg() if err != nil { - return nil, err + return "", err } switch msg := msg.(type) { case *pgproto3.ReadyForQuery: c.rxReadyForQuery(msg) - return nil, err + return "", err case *pgproto3.CommandComplete: return pgconn.CommandTag(msg.CommandTag), nil case *pgproto3.ErrorResponse: - return nil, c.rxErrorResponse(msg) + return "", c.rxErrorResponse(msg) default: - return nil, c.processContextFreeMsg(msg) + return "", c.processContextFreeMsg(msg) } } } diff --git a/copy_to.go b/copy_to.go index 3af307a3..9a9d954e 100644 --- a/copy_to.go +++ b/copy_to.go @@ -28,17 +28,17 @@ func (c *Conn) readUntilCopyOutResponse() error { func (c *Conn) CopyToWriter(w io.Writer, sql string, args ...interface{}) (pgconn.CommandTag, error) { if err := c.sendSimpleQuery(sql, args...); err != nil { - return nil, err + return "", err } if err := c.readUntilCopyOutResponse(); err != nil { - return nil, err + return "", err } for { msg, err := c.rxMsg() if err != nil { - return nil, err + return "", err } switch msg := msg.(type) { @@ -48,17 +48,17 @@ func (c *Conn) CopyToWriter(w io.Writer, sql string, args ...interface{}) (pgcon _, err := w.Write(msg.Data) if err != nil { c.die(err) - return nil, err + return "", err } case *pgproto3.ReadyForQuery: c.rxReadyForQuery(msg) - return nil, nil + return "", nil case *pgproto3.CommandComplete: return pgconn.CommandTag(msg.CommandTag), nil case *pgproto3.ErrorResponse: - return nil, c.rxErrorResponse(msg) + return "", c.rxErrorResponse(msg) default: - return nil, c.processContextFreeMsg(msg) + return "", c.processContextFreeMsg(msg) } } } diff --git a/pgmock/pgmock.go b/pgmock/pgmock.go index 04a06f50..4d15f7b8 100644 --- a/pgmock/pgmock.go +++ b/pgmock/pgmock.go @@ -224,7 +224,7 @@ where ( SendMessage(&pgproto3.ParameterDescription{}), SendMessage(&pgproto3.RowDescription{ Fields: []pgproto3.FieldDescription{ - {Name: []byte("oid"), + {Name: "oid", TableOID: 1247, TableAttributeNumber: 65534, DataTypeOID: 26, @@ -232,7 +232,7 @@ where ( TypeModifier: -1, Format: 0, }, - {Name: []byte("typname"), + {Name: "typname", TableOID: 1247, TableAttributeNumber: 1, DataTypeOID: 19, @@ -435,7 +435,7 @@ where ( steps = append(steps, step) } - steps = append(steps, SendMessage(&pgproto3.CommandComplete{CommandTag: []byte("SELECT 163")})) + steps = append(steps, SendMessage(&pgproto3.CommandComplete{CommandTag: "SELECT 163"})) steps = append(steps, SendMessage(&pgproto3.ReadyForQuery{TxStatus: 'I'})) steps = append(steps, []Step{ @@ -450,7 +450,7 @@ where ( SendMessage(&pgproto3.ParameterDescription{}), SendMessage(&pgproto3.RowDescription{ Fields: []pgproto3.FieldDescription{ - {Name: []byte("oid"), + {Name: "oid", TableOID: 1247, TableAttributeNumber: 65534, DataTypeOID: 26, @@ -458,7 +458,7 @@ where ( TypeModifier: -1, Format: 0, }, - {Name: []byte("typname"), + {Name: "typname", TableOID: 1247, TableAttributeNumber: 1, DataTypeOID: 19, @@ -475,7 +475,7 @@ where ( ExpectMessage(&pgproto3.Execute{}), ExpectMessage(&pgproto3.Sync{}), SendMessage(&pgproto3.BindComplete{}), - SendMessage(&pgproto3.CommandComplete{CommandTag: []byte("SELECT 0")}), + SendMessage(&pgproto3.CommandComplete{CommandTag: "SELECT 0"}), SendMessage(&pgproto3.ReadyForQuery{TxStatus: 'I'}), }...) @@ -491,7 +491,7 @@ where ( SendMessage(&pgproto3.ParameterDescription{}), SendMessage(&pgproto3.RowDescription{ Fields: []pgproto3.FieldDescription{ - {Name: []byte("oid"), + {Name: "oid", TableOID: 1247, TableAttributeNumber: 65534, DataTypeOID: 26, @@ -499,7 +499,7 @@ where ( TypeModifier: -1, Format: 0, }, - {Name: []byte("typname"), + {Name: "typname", TableOID: 1247, TableAttributeNumber: 1, DataTypeOID: 19, @@ -507,7 +507,7 @@ where ( TypeModifier: -1, Format: 0, }, - {Name: []byte("typbasetype"), + {Name: "typbasetype", TableOID: 1247, TableAttributeNumber: 65534, DataTypeOID: 26, @@ -524,7 +524,7 @@ where ( ExpectMessage(&pgproto3.Execute{}), ExpectMessage(&pgproto3.Sync{}), SendMessage(&pgproto3.BindComplete{}), - SendMessage(&pgproto3.CommandComplete{CommandTag: []byte("SELECT 0")}), + SendMessage(&pgproto3.CommandComplete{CommandTag: "SELECT 0"}), SendMessage(&pgproto3.ReadyForQuery{TxStatus: 'I'}), }...) diff --git a/tx.go b/tx.go index 2800ef07..4f4cc9a9 100644 --- a/tx.go +++ b/tx.go @@ -234,7 +234,7 @@ func (tx *Tx) CopyFrom(tableName Identifier, columnNames []string, rowSrc CopyFr // CopyFromReader delegates to the underlying *Conn func (tx *Tx) CopyFromReader(r io.Reader, sql string) (commandTag pgconn.CommandTag, err error) { if tx.status != TxStatusInProgress { - return nil, ErrTxClosed + return "", ErrTxClosed } return tx.conn.CopyFromReader(r, sql) @@ -243,7 +243,7 @@ func (tx *Tx) CopyFromReader(r io.Reader, sql string) (commandTag pgconn.Command // CopyToWriter delegates to the underlying *Conn func (tx *Tx) CopyToWriter(w io.Writer, sql string, args ...interface{}) (commandTag pgconn.CommandTag, err error) { if tx.status != TxStatusInProgress { - return nil, ErrTxClosed + return "", ErrTxClosed } return tx.conn.CopyToWriter(w, sql, args...)