From 226c00b4a8d7ac856a951e29fa6b6777c0765194 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 15 Feb 2016 17:00:28 +0800 Subject: [PATCH] Fix LimitAndOffset for Update --- dialect_common.go | 12 +++++++----- dialect_mssql.go | 18 ++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dialect_common.go b/dialect_common.go index 333b0b45..a1c8ff5c 100644 --- a/dialect_common.go +++ b/dialect_common.go @@ -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 } diff --git a/dialect_mssql.go b/dialect_mssql.go index 63b46e9e..2ecc27cc 100644 --- a/dialect_mssql.go +++ b/dialect_mssql.go @@ -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 }