fix issue with mssql NEXT option.

Fixes #1205
This commit is contained in:
Craig Peterson 2017-02-21 14:23:01 -07:00
parent 5050a58b45
commit c3276eb221
1 changed files with 9 additions and 5 deletions

View File

@ -129,16 +129,20 @@ func (s mssql) CurrentDatabase() (name string) {
} }
func (mssql) LimitAndOffsetSQL(limit, offset interface{}) (sql string) { func (mssql) LimitAndOffsetSQL(limit, offset interface{}) (sql string) {
if limit != nil {
if parsedLimit, err := strconv.ParseInt(fmt.Sprint(limit), 0, 0); err == nil && parsedLimit > 0 {
sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", parsedLimit)
}
}
if offset != nil { if offset != nil {
if parsedOffset, err := strconv.ParseInt(fmt.Sprint(offset), 0, 0); err == nil && parsedOffset > 0 { if parsedOffset, err := strconv.ParseInt(fmt.Sprint(offset), 0, 0); err == nil && parsedOffset > 0 {
sql += fmt.Sprintf(" OFFSET %d ROWS", parsedOffset) sql += fmt.Sprintf(" OFFSET %d ROWS", parsedOffset)
} }
} }
if limit != nil {
if parsedLimit, err := strconv.ParseInt(fmt.Sprint(limit), 0, 0); err == nil && parsedLimit > 0 {
if sql == "" {
// add default zero offset
sql += " OFFSET 0 ROWS"
}
sql += fmt.Sprintf(" FETCH NEXT %d ROWS ONLY", parsedLimit)
}
}
return return
} }