Tedious: TypeError: Cannot read property 'hasPrecision'

Created on 5 May 2016  路  18Comments  路  Source: tediousjs/tedious

I was getting this error using the mssql module so I switched to just tedious code, and I am getting the same error using minimal.js. I am guessing that there is a SQL Server setting that I need here. My DB is SQL Server 12.0.4422. I just upgraded node to v4.4.3 and upgraded all packages.

The query produces 10 records. Using mssql, it just bombs. Using the minimal.js code, it bombs _after the first record is written to console_.

Thanks!

c:\Users\hallrogera\Documents\Projects\workbench\node_modules\mssql\node_modules
\tedious\lib\metadata-parser.js:45
  if (type.hasPrecision) {
          ^

TypeError: Cannot read property 'hasPrecision' of undefined
    at readPrecision (c:\Users\hallrogera\Documents\Projects\workbench\node_modu
les\mssql\node_modules\tedious\lib\metadata-parser.js:45:11)
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\mssql\node_
modules\tedious\lib\value-parser.js:348:22
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\mssql\node_
modules\tedious\lib\token\stream-parser.js:147:9
    at Parser.awaitData (c:\Users\hallrogera\Documents\Projects\workbench\node_m
odules\mssql\node_modules\tedious\lib\token\stream-parser.js:121:9)
    at Parser.readUInt8 (c:\Users\hallrogera\Documents\Projects\workbench\node_m
odules\mssql\node_modules\tedious\lib\token\stream-parser.js:144:12)
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\mssql\node_
modules\tedious\lib\value-parser.js:345:27
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\mssql\node_
modules\tedious\lib\token\stream-parser.js:147:9
    at Parser.awaitData (c:\Users\hallrogera\Documents\Projects\workbench\node_m
odules\mssql\node_modules\tedious\lib\token\stream-parser.js:121:9)
    at Parser.readUInt8 (c:\Users\hallrogera\Documents\Projects\workbench\node_m
odules\mssql\node_modules\tedious\lib\token\stream-parser.js:144:12)
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\mssql\node_
modules\tedious\lib\value-parser.js:344:25

Most helpful comment

I reformatted your posts for you, but in the future, please use proper markdown so the code is actually readable. If you're not familiar, see https://guides.github.com/features/mastering-markdown/

All 18 comments

Using tedious straight:

c:\Users\hallrogera\Documents\Projects\workbench\node_modules\tedious\lib\metada
ta-parser.js:45
  if (type.hasPrecision) {
          ^

TypeError: Cannot read property 'hasPrecision' of undefined
    at readPrecision (c:\Users\hallrogera\Documents\Projects\workbench\node_modu
les\tedious\lib\metadata-parser.js:45:11)
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\tedious\lib
\value-parser.js:348:22
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\tedious\lib
\token\stream-parser.js:147:9
    at Parser.awaitData (c:\Users\hallrogera\Documents\Projects\workbench\node_m
odules\tedious\lib\token\stream-parser.js:121:9)
    at Parser.readUInt8 (c:\Users\hallrogera\Documents\Projects\workbench\node_m
odules\tedious\lib\token\stream-parser.js:144:12)
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\tedious\lib
\value-parser.js:345:27
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\tedious\lib
\token\stream-parser.js:147:9
    at Parser.awaitData (c:\Users\hallrogera\Documents\Projects\workbench\node_m
odules\tedious\lib\token\stream-parser.js:121:9)
    at Parser.readUInt8 (c:\Users\hallrogera\Documents\Projects\workbench\node_m
odules\tedious\lib\token\stream-parser.js:144:12)
    at c:\Users\hallrogera\Documents\Projects\workbench\node_modules\tedious\lib
\value-parser.js:344:25

You should include a complete code example which demonstrates this error.

I am using minimal.js.

var Connection = require('tedious').Connection;
var Request = require('tedious').Request;

var config = {
  server: 'DMIRT108',
  userName: 'xxx',
  password: 'yyy',
  options: {
    debug: {
      packet: true,
      data: true,
      payload: true,
      token: false,
      log: true
    },
    database: 'zzz'
    // ,encrypt: true // for Azure
  }
};

var q = "SELECT * FROM VU_TABLE_INFO WHERE [table_name] = 'STORAGE_ITEM'";

var connection = new Connection(config);

connection.on('connect', function(err) {
    // If no error, then good to go...
    executeStatement();
  }
);

connection.on('debug', function(text) {
    //console.log(text);
  }
);

function executeStatement() {
  request = new Request(q, function(err, rowCount) {
    if (err) {
      console.log(err);
    } else {
      console.log(rowCount + ' rows');
    }

    connection.close();
  });

  request.on('row', function(columns) {
    columns.forEach(function(column) {
      if (column.value === null) {
        console.log('NULL');
      } else {
        console.log(column.value);
      }
    });
  });

  request.on('done', function(rowCount, more) {
    console.log(rowCount + ' rows returned');
  });

  // In SQL Server 2000 you may need: connection.execSqlBatch(request);
  connection.execSql(request);
}

BTW, mssql works fine for a string query, but gives this error using inputs on queries

I reformatted your posts for you, but in the future, please use proper markdown so the code is actually readable. If you're not familiar, see https://guides.github.com/features/mastering-markdown/

I was not aware, thanks. :}

For sake of completeness, here is MSSQL code:

var sql = require('mssql');

sql.connect("mssql://xxx:yyy@DMIRT108/zzz").then(function() {
    new sql
        .Request()
        .input("table_name", sql.VarChar(128), "STORAGE_ITEM")
        .query("SELECT * FROM VU_TABLE_INFO WHERE [table_name] = @table_name")

        .then(function(recordset) {
            console.dir(recordset);
            conn.close();
        }).catch(function(err) {
            // ... query error checks 
        });

}).catch(function(err) {
    // ... connect error checks 
});

What's the schema of VU_TABLE_INFO?

I don't have the creation script, and I got an error when I tried to script the CREATE. Attached are screen shots of the error and the schema in MSSMS tree view. The minimal.js script does output all of the columns of the first record.

issue_160505
issue_160505_schema

What version of mssql/tedious do you use?

This query works fine against a different table. Maybe it's the SQL_VARIANT type?

SELECT * FROM [SPECIMEN_DEV].[dbo].[STORAGE_ITEM] WHERE [store_config_id] = 5

schema_storage_item_160505

You are correct, SQL_VARIANT is not supported by Tedious. Its usage is discouraged in SQL Server, so no one has ever written support for it. You may be able to use CONVERT() in your queries as a work around unless you want to create pull request adding SQL_VARIANT support to Tedious.

Actually the support was added in 1.14 (PR). I need to figure out which value causes this exception.

@patriksimek if it's supported, it should be added to https://pekim.github.io/tedious/api-datatypes.html

I agree, fixed (docs).

Well, I don't have a good recommendation on where to fix it yet, but it is most definitely NULL values that cause this. I can predict the crash location (and the number of times readPrecision() is called before it does) by shaping the SQL query; everytime a NULL is due it bombs. TIA!

In value-parser.js, in case 'Variant', the baseType for NULL is 26.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tvrprasad picture tvrprasad  路  6Comments

codethyme picture codethyme  路  7Comments

SaloniSonpal picture SaloniSonpal  路  5Comments

gladmustang picture gladmustang  路  6Comments

tvrprasad picture tvrprasad  路  5Comments