File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,38 @@ func ExampleRows_closeError() {
8888 // Output: got error: close error
8989}
9090
91+ func ExampleRows_customDriverValue () {
92+ db , mock , err := New ()
93+ if err != nil {
94+ fmt .Println ("failed to open sqlmock database:" , err )
95+ }
96+ defer db .Close ()
97+
98+ rows := NewRows ([]string {"id" , "null_int" }).
99+ AddRow (1 , 7 ).
100+ AddRow (5 , sql.NullInt64 {Int64 : 5 , Valid : true }).
101+ AddRow (2 , sql.NullInt64 {})
102+
103+ mock .ExpectQuery ("SELECT" ).WillReturnRows (rows )
104+
105+ rs , _ := db .Query ("SELECT" )
106+ defer rs .Close ()
107+
108+ for rs .Next () {
109+ var id int
110+ var num sql.NullInt64
111+ rs .Scan (& id , & num )
112+ fmt .Println ("scanned id:" , id , "and null int64:" , num )
113+ }
114+
115+ if rs .Err () != nil {
116+ fmt .Println ("got rows error:" , rs .Err ())
117+ }
118+ // Output: scanned id: 1 and null int64: {7 true}
119+ // scanned id: 5 and null int64: {5 true}
120+ // scanned id: 2 and null int64: {0 false}
121+ }
122+
91123func TestAllowsToSetRowsErrors (t * testing.T ) {
92124 t .Parallel ()
93125 db , mock , err := New ()
You can’t perform that action at this time.
0 commit comments