【问题标题】:What is the node.js equivalent of this T-SQL query这个 T-SQL 查询的 node.js 等效项是什么
【发布时间】:2016-12-11 07:51:13
【问题描述】:

用于以查询输出格式存储密码的遗留系统,

SELECT
    HASHBYTES('SHA1', CONVERT(VARCHAR, HASHBYTES('SHA1', CONVERT(NVARCHAR(4000), ’test'))) + 'mysalt')

其中密码是test,mysalt 是使用的盐。

结果类似于

0x169A0EF01AA369518D6810E14872A3A003A1F0AA

我必须使用该加密密码并创建一个节点函数才能获得与上述查询相同的结果

【问题讨论】:

  • 感谢 Marc 的格式化

标签: sql-server node.js string tsql sha1


【解决方案1】:

Node.js 不会取代 t-sql 查询。您仍将使用 t-sql 来查询您的数据库以及与数据库的 tedious 模块连接之类的东西。这是来自https://msdn.microsoft.com/library/mt715784.aspx 的示例,介绍了如何从 node.js 连接到 SQL Server 并执行查询。对executeStatement 函数进行一些修改会让你继续前进。

var Connection = require('tedious').Connection;  
    var config = {  
        userName: 'yourusername',  
        password: 'yourpassword',  
        server: 'yourserver.database.windows.net',  
        // When you connect to Azure SQL Database, you need these next options.  
        options: {encrypt: true, database: 'AdventureWorks'}  
    };  
    var connection = new Connection(config);  
    connection.on('connect', function(err) {  
        // If no error, then good to proceed.  
        console.log("Connected");  
        executeStatement();  
    });  

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

    function executeStatement() {  
        request = new Request("SELECT c.CustomerID, c.CompanyName,COUNT(soh.SalesOrderID) AS OrderCount FROM SalesLT.Customer AS c LEFT OUTER JOIN SalesLT.SalesOrderHeader AS soh ON c.CustomerID = soh.CustomerID GROUP BY c.CustomerID, c.CompanyName ORDER BY OrderCount DESC;", function(err) {  
        if (err) {  
            console.log(err);}  
        });  
        var result = "";  
        request.on('row', function(columns) {  
            columns.forEach(function(column) {  
              if (column.value === null) {  
                console.log('NULL');  
              } else {  
                result+= column.value + " ";  
              }  
            });  
            console.log(result);  
            result ="";  
        });  

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

【讨论】:

    猜你喜欢
    • 2012-08-23
    • 1970-01-01
    • 2011-01-05
    • 2016-04-28
    • 1970-01-01
    • 2013-04-14
    • 2015-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多