Skip to content

Commit 821c88e

Browse files
committed
接收值的entity参数为nil,抛出错误
1 parent fa98d68 commit 821c88e

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
v1.7.7
2+
- 接收值的entity参数为nil,抛出错误
23
- dv.InterfaceData已过时,修改为dv.IsNil()
34
- 完善文档,注释
45

DBDao.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ var errQueryRow = errors.New("->QueryRow查询出多条数据")
467467
// 只查询一个字段,需要使用这个字段的类型进行接收,目前不支持整个struct对象接收
468468
// 根据Finder和封装为指定的entity类型,entity必须是*struct类型或者基础类型的指针.把查询的数据赋值给entity,所以要求指针类型
469469
// context必须传入,不能为空
470-
// 如果数据库是null,基本类型不支持,会返回异常,不做默认值处理,Query因为是列表,会设置为默认值
471470
// QueryRow Don't be lazy to call Query to return the first one
472471
// Question 1. A selice needs to be constructed, and question 2. Other values ​​of the object passed by the caller will be discarded or overwritten
473472
// context must be passed in and cannot be empty

structFieldInfo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ func checkEntityKind(entity interface{}) (*reflect.Type, error) {
496496
// 感谢@fastabler提交的pr
497497
// oneColumnScanner 只有一个字段,而且可以直接Scan,例如string或者[]string,不需要反射StructType进行处理
498498
func sqlRowsValues(ctx context.Context, config *DataSourceConfig, valueOf *reflect.Value, typeOf *reflect.Type, rows *sql.Rows, driverValue *reflect.Value, columnTypes []*sql.ColumnType, entity interface{}, dbColumnFieldMap, exportFieldMap *map[string]reflect.StructField) error {
499-
if entity == nil && valueOf == nil {
500-
return errors.New("->sqlRowsValues-->valueOfElem为nil")
499+
if entity == nil && (valueOf == nil || valueOf.IsNil()) {
500+
return errors.New("->sqlRowsValues-->接收值的entity参数为nil")
501501
}
502502

503503
var valueOfElem reflect.Value

0 commit comments

Comments
 (0)