Don't panic!
This commit is contained in:
+7
-3
@@ -1,5 +1,9 @@
|
||||
package pgx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// DataRowReader is used by SelectFunc to process incoming rows.
|
||||
type DataRowReader struct {
|
||||
mr *MessageReader
|
||||
@@ -7,14 +11,14 @@ type DataRowReader struct {
|
||||
currentFieldIdx int
|
||||
}
|
||||
|
||||
func newDataRowReader(mr *MessageReader, fields []FieldDescription) (r *DataRowReader) {
|
||||
func newDataRowReader(mr *MessageReader, fields []FieldDescription) (r *DataRowReader, err error) {
|
||||
r = new(DataRowReader)
|
||||
r.mr = mr
|
||||
r.fields = fields
|
||||
|
||||
fieldCount := int(mr.ReadInt16())
|
||||
if fieldCount != len(fields) {
|
||||
panic("Row description field count and data row field count do not match")
|
||||
return nil, ProtocolError(fmt.Sprintf("Row description field count (%v) and data row field count (%v) do not match", len(fields), fieldCount))
|
||||
}
|
||||
|
||||
return
|
||||
@@ -34,7 +38,7 @@ func (r *DataRowReader) ReadValue() interface{} {
|
||||
case 1:
|
||||
return vt.DecodeBinary(r.mr, size)
|
||||
default:
|
||||
panic("Unknown format")
|
||||
return ProtocolError(fmt.Sprintf("Unknown field description format code: %v", fieldDescription.FormatCode))
|
||||
}
|
||||
} else {
|
||||
return r.mr.ReadString(size)
|
||||
|
||||
Reference in New Issue
Block a user