Skip to content
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

TypeError: Cannot read property 'hasPrecision' #381

Closed
rogerhall68 opened this issue May 5, 2016 · 18 comments
Closed

TypeError: Cannot read property 'hasPrecision' #381

rogerhall68 opened this issue May 5, 2016 · 18 comments

Comments

@rogerhall68
Copy link

rogerhall68 commented May 5, 2016

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
@rogerhall68
Copy link
Author

rogerhall68 commented May 5, 2016

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

@bretcope
Copy link
Member

bretcope commented May 5, 2016

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

@rogerhall68
Copy link
Author

rogerhall68 commented May 5, 2016

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);
}

@rogerhall68
Copy link
Author

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

@bretcope
Copy link
Member

bretcope commented May 5, 2016

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/

@rogerhall68
Copy link
Author

I was not aware, thanks. :}

@rogerhall68
Copy link
Author

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 
});

@bretcope
Copy link
Member

bretcope commented May 5, 2016

What's the schema of VU_TABLE_INFO?

@rogerhall68
Copy link
Author

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

@patriksimek
Copy link
Collaborator

What version of mssql/tedious do you use?

@rogerhall68
Copy link
Author

mssql@3.2.1
tedious@1.14.0

@rogerhall68
Copy link
Author

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

@bretcope
Copy link
Member

bretcope commented May 5, 2016

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.

@bretcope bretcope closed this as completed May 5, 2016
@patriksimek
Copy link
Collaborator

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

@patriksimek patriksimek reopened this May 5, 2016
@bretcope
Copy link
Member

bretcope commented May 5, 2016

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

@patriksimek
Copy link
Collaborator

patriksimek commented May 5, 2016

I agree, fixed (docs).

@rogerhall68
Copy link
Author

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!

@rogerhall68
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants