MCPcopy Create free account
hub / github.com/DATA-DOG/go-sqlmock / ExampleRows_customDriverValue

Function ExampleRows_customDriverValue

rows_test.go:164–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

162}
163
164func ExampleRows_customDriverValue() {
165 db, mock, err := New()
166 if err != nil {
167 fmt.Println("failed to open sqlmock database:", err)
168 }
169 defer db.Close()
170
171 rows := NewRows([]string{"id", "null_int"}).
172 AddRow(1, 7).
173 AddRow(5, sql.NullInt64{Int64: 5, Valid: true}).
174 AddRow(2, sql.NullInt64{})
175
176 mock.ExpectQuery("SELECT").WillReturnRows(rows)
177
178 rs, _ := db.Query("SELECT")
179 defer rs.Close()
180
181 for rs.Next() {
182 var id int
183 var num sql.NullInt64
184 rs.Scan(&id, &num)
185 fmt.Println("scanned id:", id, "and null int64:", num)
186 }
187
188 if rs.Err() != nil {
189 fmt.Println("got rows error:", rs.Err())
190 }
191 // Output: scanned id: 1 and null int64: {7 true}
192 // scanned id: 5 and null int64: {5 true}
193 // scanned id: 2 and null int64: {0 false}
194}
195
196func TestAllowsToSetRowsErrors(t *testing.T) {
197 t.Parallel()

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
NewRowsFunction · 0.85
AddRowMethod · 0.80
NextMethod · 0.80
ExpectQueryMethod · 0.65
CloseMethod · 0.45
WillReturnRowsMethod · 0.45
QueryMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…