I'm having trouble with inserting a value into a database through node.js. Here is the offending code:

sql.query(conn_str
    ,"INSERT INTO Login(email, hash, salt, firstName, lastName) VALUES(?, ?, ?, ?, ?);
      SELECT SCOPE_IDENTITY() AS 'Identity';"
    , [email, hash, salt, firstName, lastName], function(err, results){
       console.log(results)
    }

Unfortunately, the console is just echoing [], meaning results is an empty array, I suppose.

Does anyone know why the identity is not being returned? Even if it was null, why isn't results then [{Identity: null }] ?

Database is on Azure, which does have a "Scope_Identity" function, and the native client also recognises this function.

Using node package "msnodesql"

Please Help

有帮助吗?

解决方案

Found out this is a known bug in msnodesql, and apparently affects any INSERT X; SELECT X; structure, even unrelated ones.

Here is a link to the bug for anyone interested: https://github.com/WindowsAzure/node-sqlserver/issues/127

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top