简体   繁体   English

具有节点 mssql 对象的存储过程的受影响行

[英]Affected rows for stored procedure with node mssql object

I can't seem to get this working.我似乎无法让这个工作。 I have an update procedure in Azure SQL.我在 Azure SQL 中有一个更新过程。

CREATE PROCEDURE foobar
    @a int
AS
        update foo set bar=@a;
RETURN 0

I was returning the @@rowcount and trying to work with that but it means two resultsets and sloppy code on the client side.我正在返回@@rowcount 并尝试使用它,但这意味着客户端有两个结果集和草率的代码。 The client being a node.js Azure Custom API.客户端是一个 node.js Azure 自定义 API。

exports.post = function(request, response) {
    var mssql = request.service.mssql;
    var sqlParams = [request.body.a];

    var sql = "foobar ?";

    mssql.query(sql, sqlParams, {
        success: function(results) {
                response.send(statusCodes.OK, results); //return affected rows
        }
    })
};

I've tried using results.affectedRows.我试过使用 results.affectedRows。 I've tried using additional parameters in the function to get a return value.我尝试在函数中使用附加参数来获取返回值。 I've queried the database directly and receive '1 Records Affected' as a response.我直接查询了数据库并收到“1 Records Affected”作为响应。 Even when I returned the @@rowcount I had problems specifying it in the javascript.即使当我返回@@rowcount 时,我也遇到了在 javascript 中指定它的问题。 As in I was returning for results: [{"affected":1}] and attempting to access it with results[0].affected/results[0]["affected"] and various other permutations.就像我返回结果一样: [{"affected":1}]并尝试使用results[0].affected/results[0]["affected"]和其他各种排列来访问它。 I tried JSON.parse(results) and tried to access its properties then but still no go.我尝试了 JSON.parse(results) 并尝试访问它的属性,但仍然没有成功。 It takes the Azure portal so long to update each time I'm just blindly trying different things at the minute.每次我只是盲目地尝试不同的事情时,Azure 门户都需要很长时间才能更新。

Stephen斯蒂芬

Of course after all that I found the correct documentation that suggests using queryRaw instead of query and wouldn't you know it, that returns a RowCount.当然,毕竟我找到了正确的文档,建议使用 queryRaw 而不是查询,你不知道它返回一个 RowCount。

Stephen斯蒂芬

Maybe it is an update since 2015, but the answer is right here .也许这是自 2015 年以来的更新,但答案就在这里

Also, seems like affectedRows is of mysql, while mssql uses rowsAffected .另外,好像affectedRows是的MySQL,MSSQL时使用rowsAffected No queryRaw is required.不需要queryRaw

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM