()
| 93 | } |
| 94 | |
| 95 | func ExampleRows_rawBytes() { |
| 96 | db, mock, err := New() |
| 97 | if err != nil { |
| 98 | fmt.Println("failed to open sqlmock database:", err) |
| 99 | } |
| 100 | defer db.Close() |
| 101 | |
| 102 | rows := NewRows([]string{"id", "binary"}). |
| 103 | AddRow(1, []byte(`one binary value with some text!`)). |
| 104 | AddRow(2, []byte(`two binary value with even more text than the first one`)) |
| 105 | |
| 106 | mock.ExpectQuery("SELECT").WillReturnRows(rows) |
| 107 | |
| 108 | rs, _ := db.Query("SELECT") |
| 109 | defer rs.Close() |
| 110 | |
| 111 | type scanned struct { |
| 112 | id int |
| 113 | raw sql.RawBytes |
| 114 | } |
| 115 | fmt.Println("initial read...") |
| 116 | var ss []scanned |
| 117 | for rs.Next() { |
| 118 | var s scanned |
| 119 | rs.Scan(&s.id, &s.raw) |
| 120 | ss = append(ss, s) |
| 121 | fmt.Println("scanned id:", s.id, "and raw:", string(s.raw)) |
| 122 | } |
| 123 | |
| 124 | if rs.Err() != nil { |
| 125 | fmt.Println("got rows error:", rs.Err()) |
| 126 | } |
| 127 | |
| 128 | fmt.Println("after reading all...") |
| 129 | for _, s := range ss { |
| 130 | fmt.Println("scanned id:", s.id, "and raw:", string(s.raw)) |
| 131 | } |
| 132 | // Output: |
| 133 | // initial read... |
| 134 | // scanned id: 1 and raw: one binary value with some text! |
| 135 | // scanned id: 2 and raw: two binary value with even more text than the first one |
| 136 | // after reading all... |
| 137 | // scanned id: 1 and raw: ☠☠☠ MEMORY OVERWRITTEN ☠ |
| 138 | // scanned id: 2 and raw: ☠☠☠ MEMORY OVERWRITTEN ☠☠☠ ☠☠☠ MEMORY |
| 139 | } |
| 140 | |
| 141 | func ExampleRows_expectToBeClosed() { |
| 142 | db, mock, err := New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…