Skip to content

Commit b26d805

Browse files
committed
Merge pull request brianc#203 from paytm/insert_issue
Harmless select in case of invalid insert attempt
2 parents 63baf66 + 62f154d commit b26d805

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/node/query.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ var Query = Node.define({
180180
var self = this;
181181

182182
var args = sliced(arguments);
183-
if (o.length == 0) {
184-
o = {};
185-
}
186183
// object literal
187184
if (arguments.length === 1 && !o.toNode && !o.forEach) {
188185
args = [];

lib/table.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ Table.prototype.subQuery = function(alias) {
185185

186186
Table.prototype.insert = function() {
187187
var query = new Query(this);
188-
query.insert.apply(query, arguments);
188+
if(arguments[0].length == 0){
189+
query.select.call(query, this.star());
190+
query.where.apply(query,["1=2"]);
191+
} else {
192+
query.insert.apply(query, arguments);
193+
}
189194
return query;
190195
};
191196

test/dialects/insert-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ Harness.test({
409409
query: post.insert([]),
410410

411411
mysql: {
412-
text : 'INSERT INTO `post` () VALUES ()',
413-
string: 'INSERT INTO `post` () VALUES ()'
412+
text : 'SELECT `post`.* FROM `post` WHERE (1=2)',
413+
string: 'SELECT `post`.* FROM `post` WHERE (1=2)'
414414
},
415415
params: []
416416
});

0 commit comments

Comments
 (0)