不要怂,就是干,撸起袖子干!

Commit 6486f3c3 by Mick Hansen

Merge pull request #5632 from philip1986/fix-limit=0

fix limit=0 issue
2 parents f8f732ea e8a46cd1
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
"nonbsp": true, "nonbsp": true,
"maxdepth": 8, "maxdepth": 8,
"quotmark": true, // deprecated "quotmark": true, // deprecated
"-W041": false,
/* relaxing options */ /* relaxing options */
"laxbreak":true, "laxbreak":true,
"laxcomma":true, "laxcomma":true,
...@@ -44,4 +45,4 @@ ...@@ -44,4 +45,4 @@
"suiteTeardown", "suiteTeardown",
"test" "test"
] ]
} }
\ No newline at end of file
...@@ -1756,10 +1756,12 @@ var QueryGenerator = { ...@@ -1756,10 +1756,12 @@ var QueryGenerator = {
*/ */
addLimitAndOffset: function(options, model) { addLimitAndOffset: function(options, model) {
var fragment = ''; var fragment = '';
if (options.offset && !options.limit) {
/*jshint eqeqeq:false*/
if (options.offset != null && options.limit == null) {
fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + 10000000000000; fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + 10000000000000;
} else if (options.limit) { } else if (options.limit != null) {
if (options.offset) { if (options.offset != null) {
fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + this.escape(options.limit); fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + this.escape(options.limit);
} else { } else {
fragment += ' LIMIT ' + this.escape(options.limit); fragment += ' LIMIT ' + this.escape(options.limit);
......
...@@ -417,8 +417,13 @@ var QueryGenerator = { ...@@ -417,8 +417,13 @@ var QueryGenerator = {
addLimitAndOffset: function(options) { addLimitAndOffset: function(options) {
var fragment = ''; var fragment = '';
if (options.limit) fragment += ' LIMIT ' + this.escape(options.limit); /*jshint eqeqeq:false*/
if (options.offset) fragment += ' OFFSET ' + this.escape(options.offset); if (options.limit != null) {
fragment += ' LIMIT ' + this.escape(options.limit);
}
if (options.offset != null) {
fragment += ' OFFSET ' + this.escape(options.offset);
}
return fragment; return fragment;
}, },
......
...@@ -335,6 +335,16 @@ if (Support.dialectIsMySQL()) { ...@@ -335,6 +335,16 @@ if (Support.dialectIsMySQL()) {
expectation: 'SELECT * FROM `myTable` LIMIT 2, 10000000000000;', expectation: 'SELECT * FROM `myTable` LIMIT 2, 10000000000000;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'uses limit 0',
arguments: ['myTable', {limit: 0}],
expectation: 'SELECT * FROM `myTable` LIMIT 0;',
context: QueryGenerator
}, {
title: 'uses offset 0',
arguments: ['myTable', {offset: 0}],
expectation: 'SELECT * FROM `myTable` LIMIT 0, 10000000000000;',
context: QueryGenerator
}, {
title: 'multiple where arguments', title: 'multiple where arguments',
arguments: ['myTable', {where: {boat: 'canoe', weather: 'cold'}}], arguments: ['myTable', {where: {boat: 'canoe', weather: 'cold'}}],
expectation: "SELECT * FROM `myTable` WHERE `myTable`.`boat` = 'canoe' AND `myTable`.`weather` = 'cold';", expectation: "SELECT * FROM `myTable` WHERE `myTable`.`boat` = 'canoe' AND `myTable`.`weather` = 'cold';",
......
...@@ -291,7 +291,17 @@ if (dialect.match(/^postgres/)) { ...@@ -291,7 +291,17 @@ if (dialect.match(/^postgres/)) {
expectation: 'SELECT * FROM "myTable" AS "myTable" ORDER BY "myTable"."id" DESC;', expectation: 'SELECT * FROM "myTable" AS "myTable" ORDER BY "myTable"."id" DESC;',
context: QueryGenerator, context: QueryGenerator,
needsSequelize: true needsSequelize: true
},{
title: 'uses limit 0',
arguments: ['myTable', {limit: 0}],
expectation: 'SELECT * FROM "myTable" LIMIT 0;',
context: QueryGenerator
}, { }, {
title: 'uses offset 0',
arguments: ['myTable', {offset: 0}],
expectation: 'SELECT * FROM "myTable" OFFSET 0;',
context: QueryGenerator
}, {
title: 'raw arguments are neither quoted nor escaped', title: 'raw arguments are neither quoted nor escaped',
arguments: ['myTable', {order: [[{raw: 'f1(f2(id))'},'DESC']]}], arguments: ['myTable', {order: [[{raw: 'f1(f2(id))'},'DESC']]}],
expectation: 'SELECT * FROM "myTable" ORDER BY f1(f2(id)) DESC;', expectation: 'SELECT * FROM "myTable" ORDER BY f1(f2(id)) DESC;',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!