@@ -25,6 +25,7 @@ import (
25
25
26
26
var (
27
27
ColumnNameNotFound = errors .New ("column name not found" )
28
+ ColumnIsNull = errors .New ("column is null" )
28
29
)
29
30
30
31
type ResultSet struct {
@@ -81,7 +82,9 @@ func (r Row) StringByName(n string) (string, error) {
81
82
if err != nil {
82
83
return "" , err
83
84
}
84
- if s , ok := val .(string ); ! ok {
85
+ if val == nil {
86
+ return "" , ColumnIsNull
87
+ } else if s , ok := val .(string ); ! ok {
85
88
return "" , fmt .Errorf ("'%s' is not a string" , n )
86
89
} else {
87
90
return s , nil
@@ -93,8 +96,10 @@ func (r Row) InetByName(n string) (net.IP, error) {
93
96
if err != nil {
94
97
return nil , err
95
98
}
96
- if ip , ok := val .(net.IP ); ! ok {
97
- return nil , fmt .Errorf ("'%s' is not an inet" , n )
99
+ if val == nil {
100
+ return nil , ColumnIsNull
101
+ } else if ip , ok := val .(net.IP ); ! ok {
102
+ return nil , fmt .Errorf ("'%s' is not an inet (or is null)" , n )
98
103
} else {
99
104
return ip , nil
100
105
}
@@ -105,8 +110,10 @@ func (r Row) UUIDByName(n string) (primitive.UUID, error) {
105
110
if err != nil {
106
111
return [16 ]byte {}, err
107
112
}
108
- if u , ok := val .(primitive.UUID ); ! ok {
109
- return [16 ]byte {}, fmt .Errorf ("'%s' is not a uuid" , n )
113
+ if val == nil {
114
+ return [16 ]byte {}, ColumnIsNull
115
+ } else if u , ok := val .(primitive.UUID ); ! ok {
116
+ return [16 ]byte {}, fmt .Errorf ("'%s' is not a uuid (or is null)" , n )
110
117
} else {
111
118
return u , nil
112
119
}
0 commit comments