mirror of https://github.com/jackc/pgx.git
Remove Rows.Fatal
parent
0a67735a8e
commit
8322171bd8
58
query.go
58
query.go
|
@ -93,9 +93,9 @@ func (rows *Rows) Err() error {
|
||||||
return rows.err
|
return rows.err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatal signals an error occurred after the query was sent to the server. It
|
// fatal signals an error occurred after the query was sent to the server. It
|
||||||
// closes the rows automatically.
|
// closes the rows automatically.
|
||||||
func (rows *Rows) Fatal(err error) {
|
func (rows *Rows) fatal(err error) {
|
||||||
if rows.err != nil {
|
if rows.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ func (rows *Rows) Next() bool {
|
||||||
for {
|
for {
|
||||||
msg, err := rows.conn.rxMsg()
|
msg, err := rows.conn.rxMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,13 +130,13 @@ func (rows *Rows) Next() bool {
|
||||||
rows.fields[i].DataTypeName = dt.Name
|
rows.fields[i].DataTypeName = dt.Name
|
||||||
rows.fields[i].FormatCode = TextFormatCode
|
rows.fields[i].FormatCode = TextFormatCode
|
||||||
} else {
|
} else {
|
||||||
rows.Fatal(fmt.Errorf("unknown oid: %d", rows.fields[i].DataType))
|
rows.fatal(fmt.Errorf("unknown oid: %d", rows.fields[i].DataType))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *pgproto3.DataRow:
|
case *pgproto3.DataRow:
|
||||||
if len(msg.Values) != len(rows.fields) {
|
if len(msg.Values) != len(rows.fields) {
|
||||||
rows.Fatal(ProtocolError(fmt.Sprintf("Row description field count (%v) and data row field count (%v) do not match", len(rows.fields), len(msg.Values))))
|
rows.fatal(ProtocolError(fmt.Sprintf("Row description field count (%v) and data row field count (%v) do not match", len(rows.fields), len(msg.Values))))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ func (rows *Rows) Next() bool {
|
||||||
default:
|
default:
|
||||||
err = rows.conn.processContextFreeMsg(msg)
|
err = rows.conn.processContextFreeMsg(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ func (rows *Rows) nextColumn() ([]byte, *FieldDescription, bool) {
|
||||||
return nil, nil, false
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
if len(rows.fields) <= rows.columnIdx {
|
if len(rows.fields) <= rows.columnIdx {
|
||||||
rows.Fatal(ProtocolError("No next column available"))
|
rows.fatal(ProtocolError("No next column available"))
|
||||||
return nil, nil, false
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ func (e scanArgError) Error() string {
|
||||||
func (rows *Rows) Scan(dest ...interface{}) (err error) {
|
func (rows *Rows) Scan(dest ...interface{}) (err error) {
|
||||||
if len(rows.fields) != len(dest) {
|
if len(rows.fields) != len(dest) {
|
||||||
err = fmt.Errorf("Scan received wrong number of arguments, got %d but expected %d", len(dest), len(rows.fields))
|
err = fmt.Errorf("Scan received wrong number of arguments, got %d but expected %d", len(dest), len(rows.fields))
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,12 +206,12 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
|
||||||
if s, ok := d.(pgtype.BinaryDecoder); ok && fd.FormatCode == BinaryFormatCode {
|
if s, ok := d.(pgtype.BinaryDecoder); ok && fd.FormatCode == BinaryFormatCode {
|
||||||
err = s.DecodeBinary(rows.conn.ConnInfo, buf)
|
err = s.DecodeBinary(rows.conn.ConnInfo, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(scanArgError{col: i, err: err})
|
rows.fatal(scanArgError{col: i, err: err})
|
||||||
}
|
}
|
||||||
} else if s, ok := d.(pgtype.TextDecoder); ok && fd.FormatCode == TextFormatCode {
|
} else if s, ok := d.(pgtype.TextDecoder); ok && fd.FormatCode == TextFormatCode {
|
||||||
err = s.DecodeText(rows.conn.ConnInfo, buf)
|
err = s.DecodeText(rows.conn.ConnInfo, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(scanArgError{col: i, err: err})
|
rows.fatal(scanArgError{col: i, err: err})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if dt, ok := rows.conn.ConnInfo.DataTypeForOid(fd.DataType); ok {
|
if dt, ok := rows.conn.ConnInfo.DataTypeForOid(fd.DataType); ok {
|
||||||
|
@ -221,40 +221,40 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
|
||||||
if textDecoder, ok := value.(pgtype.TextDecoder); ok {
|
if textDecoder, ok := value.(pgtype.TextDecoder); ok {
|
||||||
err = textDecoder.DecodeText(rows.conn.ConnInfo, buf)
|
err = textDecoder.DecodeText(rows.conn.ConnInfo, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(scanArgError{col: i, err: err})
|
rows.fatal(scanArgError{col: i, err: err})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rows.Fatal(scanArgError{col: i, err: fmt.Errorf("%T is not a pgtype.TextDecoder", value)})
|
rows.fatal(scanArgError{col: i, err: fmt.Errorf("%T is not a pgtype.TextDecoder", value)})
|
||||||
}
|
}
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
if binaryDecoder, ok := value.(pgtype.BinaryDecoder); ok {
|
if binaryDecoder, ok := value.(pgtype.BinaryDecoder); ok {
|
||||||
err = binaryDecoder.DecodeBinary(rows.conn.ConnInfo, buf)
|
err = binaryDecoder.DecodeBinary(rows.conn.ConnInfo, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(scanArgError{col: i, err: err})
|
rows.fatal(scanArgError{col: i, err: err})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rows.Fatal(scanArgError{col: i, err: fmt.Errorf("%T is not a pgtype.BinaryDecoder", value)})
|
rows.fatal(scanArgError{col: i, err: fmt.Errorf("%T is not a pgtype.BinaryDecoder", value)})
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
rows.Fatal(scanArgError{col: i, err: fmt.Errorf("unknown format code: %v", fd.FormatCode)})
|
rows.fatal(scanArgError{col: i, err: fmt.Errorf("unknown format code: %v", fd.FormatCode)})
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows.Err() == nil {
|
if rows.Err() == nil {
|
||||||
if scanner, ok := d.(sql.Scanner); ok {
|
if scanner, ok := d.(sql.Scanner); ok {
|
||||||
sqlSrc, err := pgtype.DatabaseSQLValue(rows.conn.ConnInfo, value)
|
sqlSrc, err := pgtype.DatabaseSQLValue(rows.conn.ConnInfo, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
}
|
}
|
||||||
err = scanner.Scan(sqlSrc)
|
err = scanner.Scan(sqlSrc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(scanArgError{col: i, err: err})
|
rows.fatal(scanArgError{col: i, err: err})
|
||||||
}
|
}
|
||||||
} else if err := value.AssignTo(d); err != nil {
|
} else if err := value.AssignTo(d); err != nil {
|
||||||
rows.Fatal(scanArgError{col: i, err: err})
|
rows.fatal(scanArgError{col: i, err: err})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rows.Fatal(scanArgError{col: i, err: fmt.Errorf("unknown oid: %v", fd.DataType)})
|
rows.fatal(scanArgError{col: i, err: fmt.Errorf("unknown oid: %v", fd.DataType)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ func (rows *Rows) Values() ([]interface{}, error) {
|
||||||
}
|
}
|
||||||
err := decoder.DecodeText(rows.conn.ConnInfo, buf)
|
err := decoder.DecodeText(rows.conn.ConnInfo, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
}
|
}
|
||||||
values = append(values, decoder.(pgtype.Value).Get())
|
values = append(values, decoder.(pgtype.Value).Get())
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
|
@ -303,14 +303,14 @@ func (rows *Rows) Values() ([]interface{}, error) {
|
||||||
}
|
}
|
||||||
err := decoder.DecodeBinary(rows.conn.ConnInfo, buf)
|
err := decoder.DecodeBinary(rows.conn.ConnInfo, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
}
|
}
|
||||||
values = append(values, value.Get())
|
values = append(values, value.Get())
|
||||||
default:
|
default:
|
||||||
rows.Fatal(errors.New("Unknown format code"))
|
rows.fatal(errors.New("Unknown format code"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rows.Fatal(errors.New("Unknown type"))
|
rows.fatal(errors.New("Unknown type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows.Err() != nil {
|
if rows.Err() != nil {
|
||||||
|
@ -381,7 +381,7 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions,
|
||||||
rows = c.getRows(sql, args)
|
rows = c.getRows(sql, args)
|
||||||
|
|
||||||
if err := c.lock(); err != nil {
|
if err := c.lock(); err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return rows, err
|
return rows, err
|
||||||
}
|
}
|
||||||
rows.unlockConn = true
|
rows.unlockConn = true
|
||||||
|
@ -389,13 +389,13 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions,
|
||||||
if options != nil && options.SimpleProtocol {
|
if options != nil && options.SimpleProtocol {
|
||||||
err = c.initContext(ctx)
|
err = c.initContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return rows, err
|
return rows, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.sanitizeAndSendSimpleQuery(sql, args...)
|
err = c.sanitizeAndSendSimpleQuery(sql, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return rows, err
|
return rows, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions,
|
||||||
var err error
|
var err error
|
||||||
ps, err = c.PrepareExContext(ctx, "", sql, nil)
|
ps, err = c.PrepareExContext(ctx, "", sql, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return rows, rows.err
|
return rows, rows.err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -416,13 +416,13 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions,
|
||||||
|
|
||||||
err = c.initContext(ctx)
|
err = c.initContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return rows, err
|
return rows, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.sendPreparedQuery(ps, args...)
|
err = c.sendPreparedQuery(ps, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
err = c.termContext(err)
|
err = c.termContext(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,14 +328,14 @@ func (rc *ReplicationConn) sendReplicationModeQuery(sql string) (*Rows, error) {
|
||||||
rows := rc.c.getRows(sql, nil)
|
rows := rc.c.getRows(sql, nil)
|
||||||
|
|
||||||
if err := rc.c.lock(); err != nil {
|
if err := rc.c.lock(); err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
return rows, err
|
return rows, err
|
||||||
}
|
}
|
||||||
rows.unlockConn = true
|
rows.unlockConn = true
|
||||||
|
|
||||||
err := rc.c.sendSimpleQuery(sql)
|
err := rc.c.sendSimpleQuery(sql)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rows.Fatal(err)
|
rows.fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, err := rc.c.rxMsg()
|
msg, err := rc.c.rxMsg()
|
||||||
|
@ -351,7 +351,7 @@ func (rc *ReplicationConn) sendReplicationModeQuery(sql string) (*Rows, error) {
|
||||||
// only Oids. Not much we can do about this.
|
// only Oids. Not much we can do about this.
|
||||||
default:
|
default:
|
||||||
if e := rc.c.processContextFreeMsg(msg); e != nil {
|
if e := rc.c.processContextFreeMsg(msg); e != nil {
|
||||||
rows.Fatal(e)
|
rows.fatal(e)
|
||||||
return rows, e
|
return rows, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
v3.md
2
v3.md
|
@ -38,6 +38,8 @@ Replaced Scanner, Encoder, and PgxScanner interfaces with pgtype system
|
||||||
|
|
||||||
ConnPool.Close no longer waits for all acquired connections to be released. Instead, it immediately closes all available connections, and closes acquired connections when they are released in the same manner as ConnPool.Reset.
|
ConnPool.Close no longer waits for all acquired connections to be released. Instead, it immediately closes all available connections, and closes acquired connections when they are released in the same manner as ConnPool.Reset.
|
||||||
|
|
||||||
|
Removed Rows.Fatal(error)
|
||||||
|
|
||||||
## TODO / Possible / Investigate
|
## TODO / Possible / Investigate
|
||||||
|
|
||||||
Organize errors better
|
Organize errors better
|
||||||
|
|
Loading…
Reference in New Issue