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

Function ExampleRows_rowError

rows_test.go:43–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41}
42
43func ExampleRows_rowError() {
44 db, mock, err := New()
45 if err != nil {
46 fmt.Println("failed to open sqlmock database:", err)
47 }
48 defer db.Close()
49
50 rows := NewRows([]string{"id", "title"}).
51 AddRow(0, "one").
52 AddRow(1, "two").
53 RowError(1, fmt.Errorf("row error"))
54 mock.ExpectQuery("SELECT").WillReturnRows(rows)
55
56 rs, _ := db.Query("SELECT")
57 defer rs.Close()
58
59 for rs.Next() {
60 var id int
61 var title string
62 rs.Scan(&id, &title)
63 fmt.Println("scanned id:", id, "and title:", title)
64 }
65
66 if rs.Err() != nil {
67 fmt.Println("got rows error:", rs.Err())
68 }
69 // Output: scanned id: 0 and title: one
70 // got rows error: row error
71}
72
73func ExampleRows_closeError() {
74 db, mock, err := New()

Callers

nothing calls this directly

Calls 10

NewFunction · 0.85
NewRowsFunction · 0.85
RowErrorMethod · 0.80
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…