fix: when time is zero, let it use db default value if possible #1164
No reviewers
Labels
No Label
backport/done
backport/v1
blocked
db
oracle
db
sqlserver
duplicate
feature
cache
frontport/done
frontport/main
invalid
kind
breaking
kind
bug
kind
build
kind
dependencies
kind
docs
kind
driver
kind
enhancement
kind
feature
kind
performance
kind
proposal
kind
question
kind
refactor
kind
testing
need
feedback
need
test
proposal:accepted
RaspBerry Pi
regression
skip-changelog
upstream
wip
wontfix
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: xorm/xorm#1164
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Nanyan/master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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?
Pull request closed