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,12 +109,14 @@ func (s commonDialect) currentDatabase() (name string) {
} }
func (commonDialect) LimitAndOffsetSQL(limit, offset int) (sql string) { func (commonDialect) LimitAndOffsetSQL(limit, offset int) (sql string) {
if limit > 0 || offset > 0 {
if limit >= 0 { if limit >= 0 {
sql += fmt.Sprintf(" LIMIT %d", limit) sql += fmt.Sprintf(" LIMIT %d", limit)
} }
if offset >= 0 { if offset >= 0 {
sql += fmt.Sprintf(" OFFSET %d", offset) sql += fmt.Sprintf(" OFFSET %d", offset)
} }
}
return return
} }

View File

@ -96,10 +96,7 @@ func (s mssql) currentDatabase() (name string) {
} }
func (mssql) LimitAndOffsetSQL(limit, offset int) (sql string) { func (mssql) LimitAndOffsetSQL(limit, offset int) (sql string) {
if limit < 0 && offset < 0 { if limit > 0 || offset > 0 {
return
}
if offset < 0 { if offset < 0 {
offset = 0 offset = 0
} }
@ -109,5 +106,6 @@ func (mssql) LimitAndOffsetSQL(limit, offset int) (sql string) {
if limit >= 0 { if limit >= 0 {
sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", limit) sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", limit)
} }
}
return return
} }