解决Conversion接口ToDB() ([]byte, error)方法返回*Type值为nil时,数据类型为[]byte(nil)的… #1296

Merged
peihexian merged 2 commits from peihexian/master into master 2 years ago
peihexian commented 3 years ago (Migrated from github.com)
Owner

解决字段类型为*Type,值为nil时,插入数据变为""的bug。解决update操作时,*Type类型字段的值为nil时,数据值变成[]byte(nil)的bug,正确的情况应该是interface(nil)。

解决字段类型为*Type,值为nil时,插入数据变为""的bug。解决update操作时,*Type类型字段的值为nil时,数据值变成[]byte(nil)的bug,正确的情况应该是interface(nil)。
codecov-io commented 3 years ago (Migrated from github.com)
Owner

Codecov Report

Merging #1296 into master will decrease coverage by 0.08%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1296      +/-   ##
==========================================
- Coverage   57.41%   57.33%   -0.09%     
==========================================
  Files          44       44              
  Lines        7912     7823      -89     
==========================================
- Hits         4543     4485      -58     
+ Misses       2806     2781      -25     
+ Partials      563      557       -6
Impacted Files Coverage Δ
statement.go 68.05% <0%> (+0.19%) ⬆️
session_convert.go 22.19% <0%> (-0.1%) ⬇️
rows.go 52.38% <0%> (-3.76%) ⬇️
helpers.go 57.41% <0%> (-2.32%) ⬇️
tag.go 77.09% <0%> (-2.22%) ⬇️
engine.go 61.53% <0%> (-1.06%) ⬇️
session_update.go 56.44% <0%> (-0.18%) ⬇️
session_insert.go 56.84% <0%> (-0.12%) ⬇️
dialect_oracle.go 0% <0%> (ø) ⬆️
dialect_postgres.go 76.11% <0%> (+0.15%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73a7003...9e0cd1a. Read the comment docs.

# [Codecov](https://codecov.io/gh/go-xorm/xorm/pull/1296?src=pr&el=h1) Report > Merging [#1296](https://codecov.io/gh/go-xorm/xorm/pull/1296?src=pr&el=desc) into [master](https://codecov.io/gh/go-xorm/xorm/commit/73a7003f43e029b6dd3a620c0f8336ff19b97d5b?src=pr&el=desc) will **decrease** coverage by `0.08%`. > The diff coverage is `0%`. [![Impacted file tree graph](https://codecov.io/gh/go-xorm/xorm/pull/1296/graphs/tree.svg?width=650&token=yB5nO1krEe&height=150&src=pr)](https://codecov.io/gh/go-xorm/xorm/pull/1296?src=pr&el=tree) ```diff @@ Coverage Diff @@ ## master #1296 +/- ## ========================================== - Coverage 57.41% 57.33% -0.09% ========================================== Files 44 44 Lines 7912 7823 -89 ========================================== - Hits 4543 4485 -58 + Misses 2806 2781 -25 + Partials 563 557 -6 ``` | [Impacted Files](https://codecov.io/gh/go-xorm/xorm/pull/1296?src=pr&el=tree) | Coverage Δ | | |---|---|---| | [statement.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-c3RhdGVtZW50Lmdv) | `68.05% <0%> (+0.19%)` | :arrow_up: | | [session\_convert.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-c2Vzc2lvbl9jb252ZXJ0Lmdv) | `22.19% <0%> (-0.1%)` | :arrow_down: | | [rows.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-cm93cy5nbw==) | `52.38% <0%> (-3.76%)` | :arrow_down: | | [helpers.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-aGVscGVycy5nbw==) | `57.41% <0%> (-2.32%)` | :arrow_down: | | [tag.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-dGFnLmdv) | `77.09% <0%> (-2.22%)` | :arrow_down: | | [engine.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-ZW5naW5lLmdv) | `61.53% <0%> (-1.06%)` | :arrow_down: | | [session\_update.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-c2Vzc2lvbl91cGRhdGUuZ28=) | `56.44% <0%> (-0.18%)` | :arrow_down: | | [session\_insert.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-c2Vzc2lvbl9pbnNlcnQuZ28=) | `56.84% <0%> (-0.12%)` | :arrow_down: | | [dialect\_oracle.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-ZGlhbGVjdF9vcmFjbGUuZ28=) | `0% <0%> (ø)` | :arrow_up: | | [dialect\_postgres.go](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree#diff-ZGlhbGVjdF9wb3N0Z3Jlcy5nbw==) | `76.11% <0%> (+0.15%)` | :arrow_up: | | ... and [6 more](https://codecov.io/gh/go-xorm/xorm/pull/1296/diff?src=pr&el=tree-more) | | ------ [Continue to review full report at Codecov](https://codecov.io/gh/go-xorm/xorm/pull/1296?src=pr&el=continue). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta) > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/go-xorm/xorm/pull/1296?src=pr&el=footer). Last update [73a7003...9e0cd1a](https://codecov.io/gh/go-xorm/xorm/pull/1296?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
peihexian commented 3 years ago (Migrated from github.com)
Owner

为什么不给合并?是不是没有说清楚? 自定义类型例如 type MyTime time.Time 这种,如果在struct里面使用时是指针类型的话,例如 type Student struct {
Name string
Birthday *MyTime
} 这种情况,需要为MyTime去实现Conversion接口,向数据库写入是ToDB方面,该方法返回值类型是[]byte ,error,如果Birthday字段用户并没有输入数据值的话,也就是Birthday字段值为nil的话,ToDB方法只能返回nil,但是因为已经限定了数据类型是[]byte,所以数据库引擎在执行时给该字段赋值为[]byte(nil)这样的参数数据,这种[]byte(nil)数据库引擎是不认的,但是改为interface(nil)的话就可以正确识别为NULL,所以加了上面改动那些代码,不知道用中文说明白没有?

为什么不给合并?是不是没有说清楚? 自定义类型例如 type MyTime time.Time 这种,如果在struct里面使用时是指针类型的话,例如 type Student struct { Name string Birthday *MyTime } 这种情况,需要为MyTime去实现Conversion接口,向数据库写入是ToDB方面,该方法返回值类型是[]byte ,error,如果Birthday字段用户并没有输入数据值的话,也就是Birthday字段值为nil的话,ToDB方法只能返回nil,但是因为已经限定了数据类型是[]byte,所以数据库引擎在执行时给该字段赋值为[]byte(nil)这样的参数数据,这种[]byte(nil)数据库引擎是不认的,但是改为interface(nil)的话就可以正确识别为NULL,所以加了上面改动那些代码,不知道用中文说明白没有?
Owner

Could you add some tests?

Could you add some tests?
lunny added the
kind/enhancement
label 2 years ago
lunny added this to the 1.0.0 milestone 2 years ago
lunny closed this pull request 2 years ago
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
The pull request has been merged as 36e26e35ed.
Sign in to join this conversation.
Loading…
There is no content yet.