brianc/node-sql

Bug: 'Insert' statement turns into 'Select' statement in some scenarios

Opened this issue · 5 comments

var sql = require('sql')
var model = sql.define({
  name: 'test',
  columns: ['c1', 'c2']
})

console.log(model.insert([]).toQuery())
/*
This should throw an error as I am trying to insert nothing.
Clearly a mistake on the programmer's side

Instead, it fails silently:
-> { text: 'SELECT * FROM "test"', values: [] }

This means that the programmer won't be alerted to the mistake.
Because the query will not throw an error.
*/

This scenario should throw an error and alert the programmer. In any case, it should not turn into a select

👍 This is still an issue.

This is not a bug, but a feature #203 :)

Harmless? I disagree. What if I have billions of rows in that table? SELECT * is not harmless.

EDIT: Ok, I see issue 203 was to add the WHERE (1=2) clause. We're seeing SELECT * FROM table because our version is really old.

This is extremely difficult to debug. Can you explain why isn't the correct behavior to throw an error?

#197 explains it.
Well, not really - its just backward-compatible behavior. The correct backward-incompatible behavior would be to not generate a query.