Fix switching CommandTag back to string

pull/483/head
Jack Christensen 2019-01-05 18:53:07 -06:00
parent f02ad34d66
commit e78fd95296
7 changed files with 43 additions and 43 deletions

View File

@ -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
}
}
}

18
conn.go
View File

@ -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

View File

@ -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)

View File

@ -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)
}
}
}

View File

@ -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)
}
}
}

View File

@ -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'}),
}...)

4
tx.go
View File

@ -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...)