You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying send date strings to the database and I'm having some issues.
This is my sample query: SELECT @p0 AS a
And the parameter is: '2015-10-31 00:00:00'
I have tried these datatypes with similar result: DateTime, DateTime2, DateTimeOffset
This is the error message:
c:\Klocktornet\DISEServerWebUI\node_modules\any-db-mssql\node_modules\tedious\lib\data-type.js:1514
var offset = -parameter.value.getTimezoneOffset();
^
TypeError: undefined is not a function
at Object.writeParameterData (c:\Klocktornet\DISEServerWebUI\node_modules\any-db-mssql\node_modules\tedious\lib\data-type.js:1514:39)
at new RpcRequestPayload (c:\Klocktornet\DISEServerWebUI\node_modules\any-db-mssql\node_modules\tedious\lib\rpcrequest-payload.js:95:12)
at Connection.execSql (c:\Klocktornet\DISEServerWebUI\node_modules\any-db-mssql\node_modules\tedious\lib\connection.js:764:66)
at _execNextInQueue (c:\Klocktornet\DISEServerWebUI\node_modules\any-db-mssql\index.js:606:11)
at process._tickCallback (node.js:355:11)
The issue seems to be that the value is converted from a string to an integer in the validate method in data-type.js. The value after the conversion is 1446246000000. It seems to me that this should really be a Date object and not a number.
I can work around this bu sending in real Date objects, but I still think this is an issue that should be solved.
I also ran into this problem. The workaround is the following:
varstr="2016-03-10T19:36:16.105Z";vard=newDate(str);if(isNaN(d)){// throw error about invalid date string}else{request.addParameter('DateCreated',TYPES.DateTime,d);}
It would be nice if tedious performed this check when adding a parameter.
For example, something like the following
functionaddParameter(name,type,value){if(typeofvalue==='string'&&(type===TYPES.DateTime||type===TYPES.DateTime2)){value=newDate(value);}// ... remaining code stays the same}
parameter.value.getTimezoneOffset is not a function this method is being called on a type of object which is not a Date and throwing an error, see (npm 2.6.2) lib/data-types/smalldatetime.js near line 31.
To reproduce add a parameter that is a SmallDateTime.
npm ls
├─┬ [email protected]
error:
(node:36545) UnhandledPromiseRejectionWarning: TypeError: parameter.value.getTimezoneOffset is not a function
at Object.writeParameterData (/path/node_modules/tedious/lib/data-types/smalldatetime.js:31:37)
at new RpcRequestPayload (/path/node_modules/tedious/lib/rpcrequest-payload.js:95:12)
at Connection.execSql (/path/node_modules/tedious/lib/connection.js:1332:51)
at Promise (/path/node_modules/tedious-wrapper/index.js:216:28)
at <anonymous>
This only occurs when options.useUTC is set to false, and the parameter value is something tedious needs to parse e.g. a string containing a date. Tedious uses Date.parse to parse the string, which returns a number of milliseconds, then later tries to call getTimezoneOffset on that value.
Activity
arthurschreiber commentedon Oct 29, 2015
Can you do me a favor and check if you also face this issue with version
1.11.5?And you're right, the parameter handling code is a bit iffy.
PatrLind commentedon Oct 29, 2015
Yes, I cannot see any difference with 1.11.5
arthurschreiber commentedon Oct 29, 2015
Ok, thanks for letting me know. I just wanted to verify this was not a regression introduced in
1.12/1.13styfle commentedon Mar 10, 2016
I also ran into this problem. The workaround is the following:
It would be nice if tedious performed this check when adding a parameter.
For example, something like the following
jimmont commentedon May 23, 2018
THIS ISSUE IS NEARLY 2 YEARS OLD
parameter.value.getTimezoneOffset is not a functionthis method is being called on a type of object which is not a Date and throwing an error, see (npm 2.6.2) lib/data-types/smalldatetime.js near line 31.To reproduce add a parameter that is a SmallDateTime.
bugg2844 commentedon May 24, 2019
This only occurs when options.useUTC is set to false, and the parameter value is something tedious needs to parse e.g. a string containing a date. Tedious uses Date.parse to parse the string, which returns a number of milliseconds, then later tries to call getTimezoneOffset on that value.
bugg2844 commentedon May 24, 2019
Appears to be caused by: f360b09
bugg2844 commentedon May 24, 2019
Looks like https://github.com/tediousjs/tedious/pull/677/files will resolve it.
fix: allow using `string` values for date related parameters
fix: allow using `string` values for date related parameters
fix: allow using `string` values for date related parameters
arthurschreiber commentedon Dec 15, 2019
🎉 This issue has been resolved in version 6.6.4 🎉
The release is available on:
Your semantic-release bot 📦🚀