Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: "DELETE ... FROM ... LIMIT 0, 1" will have syntax error
  • Loading branch information
XadillaX committed Oct 21, 2016
1 parent 5c2b30c commit d2d69d3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/adapters/mysql.js
Expand Up @@ -602,9 +602,16 @@ class MySQLAdapter extends Adapter {
}

if(options.limit && options.limit.length) {
const limit = this.makeLimit(model, options.limit);
if(limit) {
sql += ` LIMIT ${limit}`;
const limit = options.limit;
if(limit.length=== 1) {
sql += ` LIMIT ${limit[0]}`;
} else if(limit[0] === 0) {
sql += ` LIMIT ${limit[1]}`;
} else {
throw new Error("Invalid limit in delete. Refer to " +
"http://dev.mysql.com/doc/refman/5.7/en/delete.html#idm139816273062400, " +
"https://www.techonthenet.com/mysql/delete_limit.php and " +
"http://stackoverflow.com/questions/7142097/mysql-delete-statement-with-limit#answer-7142118");
}
}

Expand Down

0 comments on commit d2d69d3

Please sign in to comment.