Repository navigation
Conversation
|
There are a few issues fixed with this PR: tediousjs/node-mssql#377 I've created a node that depends on node-mssql and so my node also has these datetime errors. I also notice that the node on npm is not the same code that's in this repository. How often do you publish to npm? |
| writeParameterData: function(buffer, parameter, options) { | ||
| if (parameter.value != null) { | ||
| let days, dstDiff, milliseconds, seconds, threeHundredthsOfSecond; | ||
| var time = new Date(+parameter.value); |
There was a problem hiding this comment.
What is the rationale behind this conversion?
If parameter.value is already a Date, the + operator converts it to an integer and the new Date() converts it back to a Date.
If parameter.value is a string that does not contain a number, the + operator produces a NaN.
e.g.: +'2017-10-11' ==> NaN
or: +'Wed Oct 11 2017 19:49:46 GMT+0200' ==> NaN
|
The root problem of this issue is that sometimes the parameter values are passed through A validation function like Parameter value conversion should be moved to a separate function which is then called from both Another solution would be to rename |
|
So is this something that will be changed? |
|
I think the whole conversion logic in the data-type.js module has to be revised. Conversion to integer is also faulty.
Maybe it would be better not to convert at all and just throw a |
|
I don't think that it's important to convert, the values should be passed in the correct format to begin with. However, I've seen this issue a couple places and that is the fix. It was initially posted here tediousjs/node-mssql#185 and line 1413 of data-type.js has the same code to convert DATETIME2 time = new Date(+parameter.value); I'm not a professional programmer, so if there is something that needs to be addressed in general with data-types.js then I would be glad to see it put in place. Maybe add some logic to convert and if it fails then send an error back. Currently the error is not trapped and crashed the whole process. |
|
After some more testing I have found that the problem is the node-mssql node converts the datetime into a number. See here starting on line 166 https://github.com/patriksimek/node-mssql/blob/master/lib/datatypes.js I will raise an issue there as well as this seems incorrect. |
|
tediousjs/node-mssql#546 Issue raised here |
|
I don't agree. Starting at line 166 in https://github.com/patriksimek/node-mssql/blob/master/lib/datatypes.js, |
|
You are right, I wasn't looking at it very hard. It must get converted somewhere else to a number because when it gets to the section of this file it is indeed a number type. Either way, neither of those types are a date and in node-mssql there is no possible way to send a date type so it fails. |
|
@arthurschreiber @v-suhame what do you think about automatic value conversion for SQL statement parameters and BulkLoad field values? Should Tedious try to convert the data type of values that do not match, or just throw a TypeError? Examples:
The current implementation converts values for SQL statement parameters but not for BulkLoad field values. There are some errors and discrepancies in |
Yeah, so I totally think we should not be doing any conversion between datatypes. 👍
Yup, again, this is the way to go. 😅 I think long-term, here's what we need to do (and what probably is the only sane approach to this):
Out-of-the box, If a user of Let's use the This would also solve the issue of providing conversion logic - if someone believes they really need to be able to convert String objects to DateTime values, they should be able to hook up their own data-type handler and do whatever they want. 😄 @chdh What do you think? |
|
@arthurschreiber A plug-in architecture would be a very good and flexible solution. But in the short term, we should fix the problems with the "basic" data types. This would be a small change. |
|
@chdh You're right, we need a fix in the interim and can't leave this broken. As you've worked on the BulkLoad code before, what would be you preferred way to fix this? |
|
@arthurschreiber I would just clean up the existing If we want backward compatibility, so that the PR can already be included in a Tedious 2.x release, I would add |
|
Any update on the fix? I am facing the same issue. |
|
Hey there, I've been spending a lot of time going through the internals of tedious and it's data type system. There's a lot of weird code in there (as pointed out by @chdh). I'll be opening a PR shortly that will fix this issue here by throwing a more descriptive error message when an unexpected type is passed to the different We'll have to find a better method of handling types long term, but that's a separate discussion from the error and fix proposed here. 😞 Thank you for opening this PR and getting the discussion started. ❤️ I'm really sorry this has taken a long time to start moving to a solution 😞. I really appreciate the time you spent and hope the solution I'm suggesting above is satisfactory. If not, please let us know! |
|
Any progress is good, I'll take it! |
|
Any Progress Guy??? |
|
Was this fix ever merged? I still have issues with bulk inserting DateTime types |
|
was this ever resolved? |
|
+1 |
|
@arthurschreiber, I had a different PR #907 that holds a similar change, and it already updated to the latest master. I am not sure whether that we should close this PR and get the other PR merged in? |
|
I think with the changes in #1065 and |
Fixed an error TypeError: parameter.value.getTime is not a function. Parameter needs to be converted to a date to avoid errors.