Skip to content

Commit

Permalink
fix: limit(0).offset(0) return all data (#6191)
Browse files Browse the repository at this point in the history
Co-authored-by: hanwang <hanwang.7721@bytedance.com>
  • Loading branch information
Hanwn and hanwang committed Apr 11, 2023
1 parent f0360dc commit 59ca46d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clause/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (limit Limit) MergeClause(clause *Clause) {
clause.Name = ""

if v, ok := clause.Expression.(Limit); ok {
if (limit.Limit == nil || *limit.Limit == 0) && (v.Limit != nil && *v.Limit != 0) {
if (limit.Limit == nil || *limit.Limit == 0) && v.Limit != nil {
limit.Limit = v.Limit
}

Expand Down
4 changes: 4 additions & 0 deletions clause/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func TestLimit(t *testing.T) {
[]clause.Interface{clause.Select{}, clause.From{}, clause.Limit{Limit: &limit0}},
"SELECT * FROM `users` LIMIT 0", nil,
},
{
[]clause.Interface{clause.Select{}, clause.From{}, clause.Limit{Limit: &limit0}, clause.Limit{Offset: 0}},
"SELECT * FROM `users` LIMIT 0", nil,
},
{
[]clause.Interface{clause.Select{}, clause.From{}, clause.Limit{Offset: 20}},
"SELECT * FROM `users` OFFSET 20", nil,
Expand Down

0 comments on commit 59ca46d

Please sign in to comment.