From 9b0fb2feb9c5b24ef2207699295b4fe47404e4f1 Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Wed, 8 Jun 2016 17:01:11 -0700 Subject: [PATCH] Use int64 for limit/offset values to ensure values greater than max 32-bit integer are addressable. --- dialect.go | 2 +- dialect_common.go | 2 +- dialects/mssql/mssql.go | 2 +- main.go | 4 ++-- search.go | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dialect.go b/dialect.go index 033b9555..c6bf4405 100644 --- a/dialect.go +++ b/dialect.go @@ -35,7 +35,7 @@ type Dialect interface { HasColumn(tableName string, columnName string) bool // LimitAndOffsetSQL return generated SQL with Limit and Offset, as mssql has special case - LimitAndOffsetSQL(limit, offset int) string + LimitAndOffsetSQL(limit, offset int64) string // SelectFromDummyTable return select values, for most dbs, `SELECT values` just works, mysql needs `SELECT value FROM DUAL` SelectFromDummyTable() string // LastInsertIdReturningSuffix most dbs support LastInsertId, but postgres needs to use `RETURNING` diff --git a/dialect_common.go b/dialect_common.go index 6d43fb84..814c3d65 100644 --- a/dialect_common.go +++ b/dialect_common.go @@ -122,7 +122,7 @@ func (s commonDialect) currentDatabase() (name string) { return } -func (commonDialect) LimitAndOffsetSQL(limit, offset int) (sql string) { +func (commonDialect) LimitAndOffsetSQL(limit, offset int64) (sql string) { if limit > 0 || offset > 0 { if limit >= 0 { sql += fmt.Sprintf(" LIMIT %d", limit) diff --git a/dialects/mssql/mssql.go b/dialects/mssql/mssql.go index 34eda717..502671ee 100644 --- a/dialects/mssql/mssql.go +++ b/dialects/mssql/mssql.go @@ -127,7 +127,7 @@ func (s mssql) currentDatabase() (name string) { return } -func (mssql) LimitAndOffsetSQL(limit, offset int) (sql string) { +func (mssql) LimitAndOffsetSQL(limit, offset int64) (sql string) { if limit > 0 || offset > 0 { if offset < 0 { offset = 0 diff --git a/main.go b/main.go index cd445555..b0991ad9 100644 --- a/main.go +++ b/main.go @@ -156,12 +156,12 @@ func (s *DB) Not(query interface{}, args ...interface{}) *DB { } // Limit specify the number of records to be retrieved -func (s *DB) Limit(limit int) *DB { +func (s *DB) Limit(limit int64) *DB { return s.clone().search.Limit(limit).db } // Offset specify the number of records to skip before starting to return the records -func (s *DB) Offset(offset int) *DB { +func (s *DB) Offset(offset int64) *DB { return s.clone().search.Offset(offset).db } diff --git a/search.go b/search.go index 078bd429..c40d4e56 100644 --- a/search.go +++ b/search.go @@ -15,8 +15,8 @@ type search struct { omits []string orders []string preload []searchPreload - offset int - limit int + offset int64 + limit int64 group string tableName string raw bool @@ -82,12 +82,12 @@ func (s *search) Omit(columns ...string) *search { return s } -func (s *search) Limit(limit int) *search { +func (s *search) Limit(limit int64) *search { s.limit = limit return s } -func (s *search) Offset(offset int) *search { +func (s *search) Offset(offset int64) *search { s.offset = offset return s }