Expose DataRowReader FieldDescriptions

scan-io
Jack Christensen 2014-06-20 10:46:47 -05:00
parent 772c6ca7d7
commit cc445627b0
2 changed files with 11 additions and 11 deletions

12
conn.go
View File

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

View File

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