fix: when time is zero, let it use db default value if possible
#1164
Open
Nanyan wants to merge 1 commits from Nanyan/master
into master
pull from: Nanyan/master
merge into: xorm:master
xorm:add_on_update
xorm:cantasci/added_mssql_pagination_feature
xorm:chenghuama/master
xorm:in-han/master
xorm:liuchenrang/master
xorm:lunny/belongs_to2
xorm:lunny/clickhouse
xorm:lunny/db2_support
xorm:lunny/dm_ci
xorm:lunny/exec_driver_valuer
xorm:lunny/exec_support_conversion
xorm:lunny/fix_859
xorm:lunny/fix_oracle_time
xorm:lunny/green_plum
xorm:lunny/improve_read_preformance
xorm:lunny/json_with_texts
xorm:lunny/load
xorm:lunny/more_test
xorm:lunny/oracle_ora
xorm:lunny/redis_cache_test
xorm:lunny/return_error
xorm:lunny/slight_improvement_2
xorm:lunny/test_oracle2
xorm:lunny/test_postgres_index
xorm:lunny/upgrade_cockroach_test_env
xorm:master
xorm:patch
xorm:yuanfan/bugfix
Reviewers
Request review
No reviewers
Labels
Apply labels
Clear labels
blocked
db/oracle
db/sqlserver
duplicate
feature/cache
invalid
kind/breaking
kind/bug
kind/build
kind/dependencies
kind/docs
kind/driver
kind/enhancement
kind/feature
kind/performance
kind/proposal
kind/proposal:accepted
kind/question
kind/refactor
kind/regression
kind/testing
kind/upstream
need/feedback
need/test
RaspBerry Pi
skip-changelog
wip
wontfix
No Label
blocked
db/oracle
db/sqlserver
duplicate
feature/cache
invalid
kind/breaking
kind/bug
kind/build
kind/dependencies
kind/docs
kind/driver
kind/enhancement
kind/feature
kind/performance
kind/proposal
kind/proposal:accepted
kind/question
kind/refactor
kind/regression
kind/testing
kind/upstream
need/feedback
need/test
RaspBerry Pi
skip-changelog
wip
wontfix
Milestone
Set milestone
Clear milestone
No items
No Milestone
Projects
Clear projects
No project
Assignees
Assign users
Clear assignees
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.
No due date set.
Dependencies
No dependencies set.
Reference: xorm/xorm#1164
Reference in new issue
There is no content yet.
Delete Branch 'Nanyan/master'
Deleting a branch is permanent. It CANNOT be undone. Continue?
No
Yes
fix: for time.Time field, when time is zero and db field has default value, then return nil to use db default value
Codecov Report
61.59% <100%> (ø)
64.61% <0%> (ø)
Continue to review full report at Codecov.
@Nanyan nice work! could you add some unit tests?
@lunny Can you show some unit tests currently exist for the function formatColTime or for its caller function?
You can follow
f16ce722ec/time_test.go
as examples.emm..., I'm a little bit sorry about this, now I realize this is quite complicated when considering different database.
When I have a field such as
create_time timestamp default CURRENT_TIMESTAMP not null
in MySQL Data table, then the toolxorm reverse
will generate a field in struct as: CreateTime time.Timexorm:"not null default 'CURRENT_TIMESTAMP' TIMESTAMP"
.Before I commit this fix, when I leave CreateTime as default, then in db the create_time field will be as
0001-01-01 00:00:00
, So I fix this problem. It works for MySQL database!Now I realize that, it works ok for MySQL with the INSERT sql of "INSERT INTO tbname (..., create_time) VALUES (..., null);"; BUT at least it's NOT work for Sqlite3 (which is what the testEngine used).
That is, if the time field IsZero, then it's ok for formatColTime to return nil if the col has default value for MySQL, but is not ok for Sqlite3 (and I don't known what about the others database).
As above, I thought whether we should just omit the time field if it's zero and the table's field has default setting?