2
0

Rows.Scan can ignore column with nil

fixes #130
This commit is contained in:
Jack Christensen
2016-03-24 14:22:16 -05:00
parent 4b843c0a26
commit 94052ea940
2 changed files with 40 additions and 2 deletions
+6 -2
View File
@@ -233,8 +233,8 @@ func (e scanArgError) Error() string {
// Scan reads the values from the current row into dest values positionally.
// dest can include pointers to core types, values implementing the Scanner
// interface, and []byte. []byte will skip the decoding process and directly
// copy the raw bytes received from PostgreSQL.
// interface, []byte, and nil. []byte will skip the decoding process and directly
// copy the raw bytes received from PostgreSQL. nil will skip the value entirely.
func (rows *Rows) Scan(dest ...interface{}) (err error) {
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))
@@ -245,6 +245,10 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
for i, d := range dest {
vr, _ := rows.nextColumn()
if d == nil {
continue
}
// Check for []byte first as we allow sidestepping the decoding process and retrieving the raw bytes
if b, ok := d.(*[]byte); ok {
// If it actually is a bytea then pass it through decodeBytea (so it can be decoded if it is in text format)