mirror of https://github.com/go-gorm/gorm.git
Fix LimitAndOffset for Update
This commit is contained in:
parent
9caf48035d
commit
226c00b4a8
|
@ -109,11 +109,13 @@ func (s commonDialect) currentDatabase() (name string) {
|
|||
}
|
||||
|
||||
func (commonDialect) LimitAndOffsetSQL(limit, offset int) (sql string) {
|
||||
if limit >= 0 {
|
||||
sql += fmt.Sprintf(" LIMIT %d", limit)
|
||||
}
|
||||
if offset >= 0 {
|
||||
sql += fmt.Sprintf(" OFFSET %d", offset)
|
||||
if limit > 0 || offset > 0 {
|
||||
if limit >= 0 {
|
||||
sql += fmt.Sprintf(" LIMIT %d", limit)
|
||||
}
|
||||
if offset >= 0 {
|
||||
sql += fmt.Sprintf(" OFFSET %d", offset)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -96,18 +96,16 @@ func (s mssql) currentDatabase() (name string) {
|
|||
}
|
||||
|
||||
func (mssql) LimitAndOffsetSQL(limit, offset int) (sql string) {
|
||||
if limit < 0 && offset < 0 {
|
||||
return
|
||||
}
|
||||
if limit > 0 || offset > 0 {
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
sql += fmt.Sprintf(" OFFSET %d ROWS", offset)
|
||||
|
||||
sql += fmt.Sprintf(" OFFSET %d ROWS", offset)
|
||||
|
||||
if limit >= 0 {
|
||||
sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", limit)
|
||||
if limit >= 0 {
|
||||
sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", limit)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue