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

Function ExampleRows

rows_test.go:13–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11const invalid = `☠☠☠ MEMORY OVERWRITTEN ☠☠☠ `
12
13func ExampleRows() {
14 db, mock, err := New()
15 if err != nil {
16 fmt.Println("failed to open sqlmock database:", err)
17 }
18 defer db.Close()
19
20 rows := NewRows([]string{"id", "title"}).
21 AddRow(1, "one").
22 AddRow(2, "two")
23
24 mock.ExpectQuery("SELECT").WillReturnRows(rows)
25
26 rs, _ := db.Query("SELECT")
27 defer rs.Close()
28
29 for rs.Next() {
30 var id int
31 var title string
32 rs.Scan(&id, &title)
33 fmt.Println("scanned id:", id, "and title:", title)
34 }
35
36 if rs.Err() != nil {
37 fmt.Println("got rows error:", rs.Err())
38 }
39 // Output: scanned id: 1 and title: one
40 // scanned id: 2 and title: two
41}
42
43func ExampleRows_rowError() {
44 db, mock, err := New()

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…