Browse Source

Fix issue when calling insert with an object that has a length property instead of an array. (#337)

master
Kyle Lilly 8 years ago
committed by Brian C
parent
commit
301840e434
  1. 2
      lib/table.js
  2. 25
      test/dialects/insert-tests.js
  3. 2
      test/dialects/support.js

2
lib/table.js

@ -208,7 +208,7 @@ Table.prototype.subQuery = function(alias) {
Table.prototype.insert = function() {
var query = new Query(this);
if(arguments[0].length === 0){
if(!arguments[0] || (util.isArray(arguments[0]) && arguments[0].length === 0)){
query.select.call(query, this.star());
query.where.apply(query,["1=2"]);
} else {

25
test/dialects/insert-tests.js

@ -57,6 +57,31 @@ Harness.test({
params: ['whoah']
});
Harness.test({
query: post.insert({length: 0}),
pg: {
text : 'INSERT INTO "post" ("length") VALUES ($1)',
string: 'INSERT INTO "post" ("length") VALUES (0)'
},
sqlite: {
text : 'INSERT INTO "post" ("length") VALUES ($1)',
string: 'INSERT INTO "post" ("length") VALUES (0)'
},
mysql: {
text : 'INSERT INTO `post` (`length`) VALUES (?)',
string: 'INSERT INTO `post` (`length`) VALUES (0)'
},
mssql: {
text : 'INSERT INTO [post] ([length]) VALUES (@1)',
string: 'INSERT INTO [post] ([length]) VALUES (0)'
},
oracle: {
text : 'INSERT INTO "post" ("length") VALUES (:1)',
string: 'INSERT INTO "post" ("length") VALUES (0)'
},
params: [0]
});
Harness.test({
query: post.insert({
content: 'test',

2
test/dialects/support.js

@ -76,7 +76,7 @@ module.exports = {
definePostTable: function() {
return Table.define({
name: 'post',
columns: ['id', 'userId', 'content', 'tags']
columns: ['id', 'userId', 'content', 'tags', 'length']
});
},

Loading…
Cancel
Save