mirror of https://github.com/jackc/pgx.git
Expose DataRowReader FieldDescriptions
parent
772c6ca7d7
commit
cc445627b0
12
conn.go
12
conn.go
|
@ -410,8 +410,8 @@ func (c *Conn) SelectValue(sql string, arguments ...interface{}) (interface{}, e
|
|||
var v interface{}
|
||||
|
||||
onDataRow := func(r *DataRowReader) error {
|
||||
if len(r.fields) != 1 {
|
||||
return UnexpectedColumnCountError{ExpectedCount: 1, ActualCount: int16(len(r.fields))}
|
||||
if len(r.FieldDescriptions) != 1 {
|
||||
return UnexpectedColumnCountError{ExpectedCount: 1, ActualCount: int16(len(r.FieldDescriptions))}
|
||||
}
|
||||
|
||||
numRowsFound++
|
||||
|
@ -559,8 +559,8 @@ func (c *Conn) SelectValues(sql string, arguments ...interface{}) ([]interface{}
|
|||
|
||||
values := make([]interface{}, 0, 8)
|
||||
onDataRow := func(r *DataRowReader) error {
|
||||
if len(r.fields) != 1 {
|
||||
return UnexpectedColumnCountError{ExpectedCount: 1, ActualCount: int16(len(r.fields))}
|
||||
if len(r.FieldDescriptions) != 1 {
|
||||
return UnexpectedColumnCountError{ExpectedCount: 1, ActualCount: int16(len(r.FieldDescriptions))}
|
||||
}
|
||||
|
||||
values = append(values, r.ReadValue())
|
||||
|
@ -1079,11 +1079,11 @@ func (c *Conn) rxParameterDescription(r *MessageReader) (parameters []Oid) {
|
|||
}
|
||||
|
||||
func (c *Conn) rxDataRow(r *DataRowReader) (row map[string]interface{}) {
|
||||
fieldCount := len(r.fields)
|
||||
fieldCount := len(r.FieldDescriptions)
|
||||
|
||||
row = make(map[string]interface{}, fieldCount)
|
||||
for i := 0; i < fieldCount; i++ {
|
||||
row[r.fields[i].Name] = r.ReadValue()
|
||||
row[r.FieldDescriptions[i].Name] = r.ReadValue()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -6,15 +6,15 @@ import (
|
|||
|
||||
// DataRowReader is used by SelectFunc to process incoming rows.
|
||||
type DataRowReader struct {
|
||||
mr *MessageReader
|
||||
fields []FieldDescription
|
||||
currentFieldIdx int
|
||||
mr *MessageReader
|
||||
FieldDescriptions []FieldDescription
|
||||
currentFieldIdx int
|
||||
}
|
||||
|
||||
func newDataRowReader(mr *MessageReader, fields []FieldDescription) (r *DataRowReader, err error) {
|
||||
r = new(DataRowReader)
|
||||
r.mr = mr
|
||||
r.fields = fields
|
||||
r.FieldDescriptions = fields
|
||||
|
||||
fieldCount := int(mr.ReadInt16())
|
||||
if fieldCount != len(fields) {
|
||||
|
@ -26,7 +26,7 @@ func newDataRowReader(mr *MessageReader, fields []FieldDescription) (r *DataRowR
|
|||
|
||||
// ReadValue returns the next value from the current row.
|
||||
func (r *DataRowReader) ReadValue() interface{} {
|
||||
fieldDescription := r.fields[r.currentFieldIdx]
|
||||
fieldDescription := r.FieldDescriptions[r.currentFieldIdx]
|
||||
r.currentFieldIdx++
|
||||
|
||||
size := r.mr.ReadInt32()
|
||||
|
|
Loading…
Reference in New Issue