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

Method AddRow

rows.go:167–190  ·  view source on GitHub ↗

AddRow composed from database driver.Value slice return the same instance to perform subsequent actions. Note that the number of values must match the number of columns

(values ...driver.Value)

Source from the content-addressed store, hash-verified

165// Note that the number of values must match the number
166// of columns
167func (r *Rows) AddRow(values ...driver.Value) *Rows {
168 if len(values) != len(r.cols) {
169 panic(fmt.Sprintf("Expected number of values to match number of columns: expected %d, actual %d", len(values), len(r.cols)))
170 }
171
172 row := make([]driver.Value, len(r.cols))
173 for i, v := range values {
174 // Convert user-friendly values (such as int or driver.Valuer)
175 // to database/sql native value (driver.Value such as int64)
176 var err error
177 v, err = r.converter.ConvertValue(v)
178 if err != nil {
179 panic(fmt.Errorf(
180 "row #%d, column #%d (%q) type %T: %s",
181 len(r.rows)+1, i, r.cols[i], values[i], err,
182 ))
183 }
184
185 row[i] = v
186 }
187
188 r.rows = append(r.rows, row)
189 return r
190}
191
192// AddRows adds multiple rows composed from database driver.Value slice and
193// returns the same instance to perform subsequent actions.

Callers 15

TestAddRowExpectPanicFunction · 0.95
AddRowsMethod · 0.95
TestMockQueryTypesFunction · 0.95
ExampleRowsFunction · 0.80
ExampleRows_rowErrorFunction · 0.80
ExampleRows_rawBytesFunction · 0.80
TestRowsClosedFunction · 0.80
TestQuerySingleRowFunction · 0.80

Calls 1

ConvertValueMethod · 0.45

Tested by 15

TestAddRowExpectPanicFunction · 0.76
TestMockQueryTypesFunction · 0.76
ExampleRowsFunction · 0.64
ExampleRows_rowErrorFunction · 0.64
ExampleRows_rawBytesFunction · 0.64
TestRowsClosedFunction · 0.64
TestQuerySingleRowFunction · 0.64