Skip to content

Unexpected results when using WHERE together with ? and null #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
afanasy opened this issue Apr 19, 2018 · 1 comment
Closed

Unexpected results when using WHERE together with ? and null #32

afanasy opened this issue Apr 19, 2018 · 1 comment
Assignees
Labels

Comments

@afanasy
Copy link

afanasy commented Apr 19, 2018

Using WHERE + ? + null may lead to unexpected results

var sql = SqlString.format('DELETE FROM posts WHERE ?', {id: null});
console.log(sql); //DELETE FROM posts WHERE `id` = NULL
//will do nothing (unexpected), need to use IS NULL instead
var sql = SqlString.format('DELETE FROM posts WHERE ?', {id: 1});
console.log(sql); //DELETE FROM posts WHERE `id` = 1
//will do (expected)

I know it's not exactly this package problem, because the query is still correct, but it may be worth mentioning this in the docs.

@dougwilson
Copy link
Member

It's already in the docs:

Objects are turned into key = 'val' pairs for each enumerable property on the object. If the property's value is a function, it is skipped; if the property's value is an object, toString() is called on it and the returned value is used.

We never show doing WHERE ? anywhere, either.

@dougwilson dougwilson self-assigned this Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants