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

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 @@
"nonbsp": true,
"maxdepth": 8,
"quotmark": true, // deprecated
"-W041": false,
/* relaxing options */
"laxbreak":true,
"laxcomma":true,
......@@ -44,4 +45,4 @@
"suiteTeardown",
"test"
]
}
\ No newline at end of file
}
......@@ -1756,10 +1756,12 @@ var QueryGenerator = {
*/
addLimitAndOffset: function(options, model) {
var fragment = '';
if (options.offset && !options.limit) {
/*jshint eqeqeq:false*/
if (options.offset != null && options.limit == null) {
fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + 10000000000000;
} else if (options.limit) {
if (options.offset) {
} else if (options.limit != null) {
if (options.offset != null) {
fragment += ' LIMIT ' + this.escape(options.offset) + ', ' + this.escape(options.limit);
} else {
fragment += ' LIMIT ' + this.escape(options.limit);
......
......@@ -417,8 +417,13 @@ var QueryGenerator = {
addLimitAndOffset: function(options) {
var fragment = '';
if (options.limit) fragment += ' LIMIT ' + this.escape(options.limit);
if (options.offset) fragment += ' OFFSET ' + this.escape(options.offset);
/*jshint eqeqeq:false*/
if (options.limit != null) {
fragment += ' LIMIT ' + this.escape(options.limit);
}
if (options.offset != null) {
fragment += ' OFFSET ' + this.escape(options.offset);
}
return fragment;
},
......
......@@ -335,6 +335,16 @@ if (Support.dialectIsMySQL()) {
expectation: 'SELECT * FROM `myTable` LIMIT 2, 10000000000000;',
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',
arguments: ['myTable', {where: {boat: 'canoe', weather: 'cold'}}],
expectation: "SELECT * FROM `myTable` WHERE `myTable`.`boat` = 'canoe' AND `myTable`.`weather` = 'cold';",
......
......@@ -291,7 +291,17 @@ if (dialect.match(/^postgres/)) {
expectation: 'SELECT * FROM "myTable" AS "myTable" ORDER BY "myTable"."id" DESC;',
context: QueryGenerator,
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',
arguments: ['myTable', {order: [[{raw: '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!