2
0

Allow reading a result row multiple times

refs #478
This commit is contained in:
Jack Christensen
2019-08-31 10:50:14 -05:00
parent f20f026b7d
commit 53921a0a22
2 changed files with 50 additions and 20 deletions
+5 -20
View File
@@ -81,7 +81,6 @@ type connRows struct {
connInfo *pgtype.ConnInfo
values [][]byte
rowCount int
columnIdx int
err error
startTime time.Time
sql string
@@ -151,7 +150,6 @@ func (rows *connRows) Next() bool {
if rows.resultReader.NextRow() {
rows.rowCount++
rows.columnIdx = 0
rows.values = rows.resultReader.Values()
return true
} else {
@@ -160,21 +158,6 @@ func (rows *connRows) Next() bool {
}
}
func (rows *connRows) nextColumn() ([]byte, *pgproto3.FieldDescription, bool) {
if rows.closed {
return nil, nil, false
}
if len(rows.FieldDescriptions()) <= rows.columnIdx {
rows.fatal(errors.New("No next column available"))
return nil, nil, false
}
buf := rows.values[rows.columnIdx]
fd := &rows.FieldDescriptions()[rows.columnIdx]
rows.columnIdx++
return buf, fd, true
}
func (rows *connRows) Scan(dest ...interface{}) error {
if len(rows.FieldDescriptions()) != len(dest) {
err := errors.Errorf("Scan received wrong number of arguments, got %d but expected %d", len(dest), len(rows.FieldDescriptions()))
@@ -183,7 +166,8 @@ func (rows *connRows) Scan(dest ...interface{}) error {
}
for i, d := range dest {
buf, fd, _ := rows.nextColumn()
buf := rows.values[i]
fd := &rows.FieldDescriptions()[i]
if d == nil {
continue
@@ -206,8 +190,9 @@ func (rows *connRows) Values() ([]interface{}, error) {
values := make([]interface{}, 0, len(rows.FieldDescriptions()))
for range rows.FieldDescriptions() {
buf, fd, _ := rows.nextColumn()
for i := range rows.FieldDescriptions() {
buf := rows.values[i]
fd := &rows.FieldDescriptions()[i]
if buf == nil {
values = append(values, nil)