Accept 0 as a value for Limit, Offset

This commit is contained in:
Jinzhu 2017-04-18 23:31:56 +08:00
parent b21c0bef9b
commit a870874bb5
2 changed files with 4 additions and 4 deletions

View File

@ -124,12 +124,12 @@ func (s commonDialect) CurrentDatabase() (name string) {
func (commonDialect) LimitAndOffsetSQL(limit, offset interface{}) (sql string) { func (commonDialect) LimitAndOffsetSQL(limit, offset interface{}) (sql string) {
if limit != nil { if limit != nil {
if parsedLimit, err := strconv.ParseInt(fmt.Sprint(limit), 0, 0); err == nil && parsedLimit > 0 { if parsedLimit, err := strconv.ParseInt(fmt.Sprint(limit), 0, 0); err == nil && parsedLimit >= 0 {
sql += fmt.Sprintf(" LIMIT %d", parsedLimit) sql += fmt.Sprintf(" LIMIT %d", 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", parsedOffset) sql += fmt.Sprintf(" OFFSET %d", parsedOffset)
} }
} }

View File

@ -145,12 +145,12 @@ func (s mssql) CurrentDatabase() (name string) {
func (mssql) LimitAndOffsetSQL(limit, offset interface{}) (sql string) { func (mssql) LimitAndOffsetSQL(limit, offset interface{}) (sql string) {
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 limit != nil {
if parsedLimit, err := strconv.ParseInt(fmt.Sprint(limit), 0, 0); err == nil && parsedLimit > 0 { if parsedLimit, err := strconv.ParseInt(fmt.Sprint(limit), 0, 0); err == nil && parsedLimit >= 0 {
if sql == "" { if sql == "" {
// add default zero offset // add default zero offset
sql += " OFFSET 0 ROWS" sql += " OFFSET 0 ROWS"