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
varrequest=newsql.Request(connection);request.query("with tt1 as ( select * from t1 ), "+" tt2 as (select count(c1) as x from tt1) "+" select * from tt2, tt1 ",function(err,recordset){if(err)returndone(err);assert.equal(recordset.length,1,'There should be a result set');vartt2type=recordset.columns.x.type;varc1type=recordset.columns.c1.type;varc2type=recordset.columns.c2.type;assert.equal(tt2type,sql.Int);assert.equal(c1type,sql.BigInt);assert.equal(c2type,sql.Int);done();});
But the following code fails as c1type becomes sql.Int
varrequest=newsql.Request(connection);request.query("with tt1 as ( select * from t1 ), "+" tt2 as (select count(c1) as x from tt1) "+" select * from tt2 left outer join tt1 on 1=1 ",function(err,recordset){if(err)returndone(err);assert.equal(recordset.length,1,'There should be a result set');vartt2type=recordset.columns.x.type;varc1type=recordset.columns.c1.type;varc2type=recordset.columns.c2.type;assert.equal(tt2type,sql.Int);assert.equal(c1type,sql.BigInt);//This fails because now c1type === sql.Intassert.equal(c2type,sql.Int);done();});
To me it seems that the metadata-parser is too simple. It correctly interprets the byte stream returned by the server (it says in the second example 0x38 which is in fact TYPE.Int) but does not consider dataLength at all.
For example for the example above, a TYPE.Int with a dataLength of 8 should become a TYPE.BigInt. And there are a lot of other situations where the dataLength alters the type.
For those who stumble across the same problem, my workaround for the moment is this.
What it should be - I.e. while handling this tediousjs/tedious#163:
This whole issue seems to be an edge case because it happens only sometimes.
Therefore sorry in advance for all the text that follows.
I condensed the problem to the following problem so you may reproduce it (seen on MSSQL 2012 Std and Dev):
Given the following database setup:
The following code just works fine
But the following code fails as
c1type
becomessql.Int
To me it seems that the
metadata-parser
is too simple. It correctly interprets the byte stream returned by the server (it says in the second example0x38
which is in factTYPE.Int
) but does not considerdataLength
at all.For example for the example above, a
TYPE.Int
with adataLength
of8
should become aTYPE.BigInt
. And there are a lot of other situations where thedataLength
alters thetype
.The Java-guys from jTDS have a quite comprehensive list of this "type promotions":
http://grepcode.com/file/repo1.maven.org/maven2/net.sourceforge.jtds/jtds/1.3.1/net/sourceforge/jtds/jdbc/TdsData.java/#467
For those who stumble across the same problem, my workaround for the moment is this.
What it should be - I.e. while handling this tediousjs/tedious#163:
Workaround
The text was updated successfully, but these errors were encountered: