Fix LimitAndOffset for Update

This commit is contained in:
Jinzhu 2016-02-15 17:00:28 +08:00
parent 9caf48035d
commit 226c00b4a8
2 changed files with 15 additions and 15 deletions

View File

@ -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
}

View File

@ -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
}