MCPcopy
hub / github.com/go-gorm/gorm / TestScanRowsNullValuesScanToFieldDefault

Function TestScanRowsNullValuesScanToFieldDefault

tests/scan_test.go:166–262  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

164}
165
166func TestScanRowsNullValuesScanToFieldDefault(t *testing.T) {
167 DB.Save(&User{})
168
169 rows, err := DB.Table("users").
170 Select(`
171 NULL AS bool_field,
172 NULL AS int_field,
173 NULL AS int8_field,
174 NULL AS int16_field,
175 NULL AS int32_field,
176 NULL AS int64_field,
177 NULL AS uint_field,
178 NULL AS uint8_field,
179 NULL AS uint16_field,
180 NULL AS uint32_field,
181 NULL AS uint64_field,
182 NULL AS float32_field,
183 NULL AS float64_field,
184 NULL AS string_field,
185 NULL AS time_field,
186 NULL AS time_ptr_field,
187 NULL AS embedded_int_field,
188 NULL AS nested_embedded_int_field,
189 NULL AS embedded_ptr_int_field
190 `).Rows()
191 if err != nil {
192 t.Errorf("No error should happen, got %v", err)
193 }
194
195 type NestedEmbeddedStruct struct {
196 NestedEmbeddedIntField int
197 NestedEmbeddedIntFieldWithDefault int `gorm:"default:2"`
198 }
199
200 type EmbeddedStruct struct {
201 EmbeddedIntField int
202 NestedEmbeddedStruct `gorm:"embedded"`
203 }
204
205 type EmbeddedPtrStruct struct {
206 EmbeddedPtrIntField int
207 *NestedEmbeddedStruct `gorm:"embedded"`
208 }
209
210 type Result struct {
211 BoolField bool
212 IntField int
213 Int8Field int8
214 Int16Field int16
215 Int32Field int32
216 Int64Field int64
217 UIntField uint
218 UInt8Field uint8
219 UInt16Field uint16
220 UInt32Field uint32
221 UInt64Field uint64
222 Float32Field float32
223 Float64Field float64

Callers

nothing calls this directly

Calls 6

SaveMethod · 0.80
NextMethod · 0.80
ScanRowsMethod · 0.80
RowsMethod · 0.65
SelectMethod · 0.65
TableMethod · 0.65

Tested by

no test coverage detected