Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed May 9, 2019
1 parent 995bc64 commit 1fa56cf
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -4734,6 +4734,7 @@ func (c *periodAddFunctionClass) getFunction(ctx sessionctx.Context, args []Expr
return sig, nil
}

// validPeriod checks if this period is valid, it comes from MySQL 8.0+.
func validPeriod(p int64) bool {
return !(p < 0 || p%100 == 0 || p%100 > 12)
}
Expand Down Expand Up @@ -4794,6 +4795,7 @@ func (b *builtinPeriodAddSig) evalInt(row chunk.Row) (int64, bool, error) {
return 0, true, err
}

// in MySQL, if p is invalid but n is NULL, the result is NULL, so we have to check if n is NULL first.
if !validPeriod(p) {
return 0, false, errIncorrectArgs.GenWithStackByArgs("period_add")
}
Expand Down

0 comments on commit 1fa56cf

Please sign in to comment.