()
| 162 | } |
| 163 | |
| 164 | func 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 | |
| 196 | func TestAllowsToSetRowsErrors(t *testing.T) { |
| 197 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…