-
Notifications
You must be signed in to change notification settings - Fork 78
Convert invalid dates to null #10
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
Conversation
haha, the |
I'm using "Invalid date" for this:
that way it's still a |
Oh, @sidorares , this is for the opposite direction: JavaScript -> SQL (rather than SQL -> JavaScript). |
oh, sorry, get it now. What's expected behaviour for server then? Receive it as 0:0:0 date? |
So given var date = new Date(NaN)
var sql = SqlString.format('SELECT * FROM archive WHERE date >= ?', [date]) here is what this module does right now: SELECT * FROM archive WHERE date >= '0NaN-NaN-NaN NaN:NaN:NaN.NaN' And this PR currently proposes that becomes SELECT * FROM archive WHERE date >= 'null' In fact, I actually thought this made the above What I was originally mulling was should the above be |
I think DateTime field can be CREATE TABLE demo (
id INT IDENTITY(1,1) NOT NULL,
fooDate DATETIME NULL,
PRIMARY KEY (id)) |
NULL would make more sense than 'null' imo |
Cool, so I thought that the PR doing But, I guess it sounds like everyone is in agreement on the |
I do return |
Do I need to return |
I would not return NULL but rather an exception or some kind of error that makes it clear that an invalid date was passed. |
The intention of this lib is to escape js stuff to valid safe MySQL syntax. |
Right, at least in the current form, the intent of this lib is to escape what was given in some way and try to avoid throwing.
I can always fix it :) but when I looked, the reason is that in the main escape function, your null is passed to the string escape function, as it currently assumes all those functions will return a string. We would just need to add a check for null return value and return 'NULL' from escape (sorry for the brevity; typing this on a phone). Also, on the NULL vs zero date, I was thinking about it and had some additional thoughts I'll type up a bit later when I get to a computer :) |
@dougwilson I'll wait until you typed your comments then (and would returning |
@dougwilson friendly ping for your thoughts ;) |
Hi @AdriVanHoudt , sorry, I didn't forget, but just kept running out of times in my sit downs :) So here are my thoughts I wanted to lay out: I feel generally that Since Anyway, those are my thoughts. Not really arguing for any change, but wanted to write them down here, especially if someone comes questioning the decision :) Unless there is any argument, we'll just land this as |
No problem just wanted to make sure ;) |
Sorry, lost track of this for a bit :) Fixed it up to return |
So I had a case where I received an invalid date and did wrap it myself with
new Date()
but this module was parsing the invalid date to0NaN-NaN-NaN NaN:NaN:NaN.NaN
.Now I fixed this to be converted to null, what I assume is the behaviour people expect from the module but if this is not the case I am open for discussion ofc.
(Also looking forward to getting another beer with you like in Amsterdam, @dougwilson!)