// Code derived from https://github.com/sequelize/sequelize
// Based on:
//  https://github.com/sequelize/sequelize/commit/d198d78182cbf1ea3ef1706740b35813a6aa0838
// https://github.com/sequelize/sequelize/blob/master/LICENSE
/*
Copyright (c) 2014-2016 Sequelize contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
diff --git a/lib/dialects/abstract/query-generator.js b/lib/dialects/abstract/query-generator.js
index 568b219..aec1245 100644
--- a/lib/dialects/abstract/query-generator.js
+++ b/lib/dialects/abstract/query-generator.js
@@ -1765,12 +1765,12 @@ var QueryGenerator = {
   addLimitAndOffset: function(options, model) {
     var fragment = '';
     if (options.offset && !options.limit) {
-      fragment += ' LIMIT ' + options.offset + ', ' + 18440000000000000000;
+      fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + 18440000000000000000;
     } else if (options.limit) {
       if (options.offset) {
-        fragment += ' LIMIT ' + options.offset + ', ' + options.limit;
+        fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + this.escape(options.limit);
       } else {
-        fragment += ' LIMIT ' + options.limit;
+        fragment += ' LIMIT ' + this.escape(options.limit);
       }
     }
 
diff --git a/lib/dialects/mssql/query-generator.js b/lib/dialects/mssql/query-generator.js
index e634159..9497125 100644
--- a/lib/dialects/mssql/query-generator.js
+++ b/lib/dialects/mssql/query-generator.js
@@ -590,11 +590,11 @@ var QueryGenerator = {
       }
 
       if (options.offset || options.limit) {
-        fragment += ' OFFSET ' + offset + ' ROWS';
+        fragment += ' OFFSET ' + this.escape(offset) + ' ROWS';
       }
 
       if (options.limit) {
-        fragment += ' FETCH NEXT ' + options.limit + ' ROWS ONLY';
+        fragment += ' FETCH NEXT ' + this.escape(options.limit) + ' ROWS ONLY';
       }
     }
 
diff --git a/lib/dialects/postgres/query-generator.js b/lib/dialects/postgres/query-generator.js
index 7ff65d1..8974dcc 100644
--- a/lib/dialects/postgres/query-generator.js
+++ b/lib/dialects/postgres/query-generator.js
@@ -423,8 +423,8 @@ var QueryGenerator = {
 
   addLimitAndOffset: function(options) {
     var fragment = '';
-    if (options.limit) fragment += ' LIMIT ' + options.limit;
-    if (options.offset) fragment += ' OFFSET ' + options.offset;
+    if (options.limit) fragment += ' LIMIT ' + this.escape(options.limit);
+    if (options.offset) fragment += ' OFFSET ' + this.escape(options.offset);
 
     return fragment;
   },
diff --git a/lib/dialects/sqlite/query-generator.js b/lib/dialects/sqlite/query-generator.js
index ab73ac0..5d343f2 100644
--- a/lib/dialects/sqlite/query-generator.js
+++ b/lib/dialects/sqlite/query-generator.js
@@ -91,12 +91,12 @@
   addLimitAndOffset: function(options){
     var fragment = '';
     if (options.offset && !options.limit) {
-      fragment += ' LIMIT ' + options.offset + ', ' + 10000000000000;
+      fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + 10000000000000;
     } else if (options.limit) {
       if (options.offset) {
-        fragment += ' LIMIT ' + options.offset + ', ' + options.limit;
+        fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + this.escape(options.limit);
       } else {
-        fragment += ' LIMIT ' + options.limit;
+        fragment += ' LIMIT ' + this.escape(options.limit);
       }
     }
