2016-03-07 33 views
0

。 记录是不确定的,当我尝试使用准备语句表中插入记录。以下是代码示例。使用准备语句插入数据不会返回我使用<a href="https://github.com/patriksimek/node-mssql" rel="nofollow">node-sql</a>插入的记录

ps.execute(data, function (err, recordSet, affected) { }); 

尽管记录已成功插入到数据库中,但它在回调函数中给出了未定义的变量。

+0

什么是没有被检索的记录集的期望值? – AhsanAyaz

回答

0

是的,我找到了答案,我们需要指定记录使用OUTPUT子句返回。像:

INSERT INTO Table OUTPUT.Id VALUES(...); 
0

你不同意你的说法实际上做。但是,如果您使用准备语句插入记录。那么您可以使用“returnValue”或“affected”回调参数代替recordSet。如果你正在运行选择的查询将返回一些记录 作为节点SQL状态记录集将有值。 见

request.execute('record', function(err, recordsets, returnValue, affected) { 
    // ... error checks 

    console.log(recordsets.length); // count of recordsets returned by the procedure 
    console.log(recordsets[0].length); // count of rows contained in first recordset 
    console.log(returnValue); // procedure return value 
    console.log(recordsets.returnValue); // same as previous line 
    console.log(affected); // number of rows affected by the statemens 
    console.log(recordsets.rowsAffected); // same as previous line 

    console.log(request.parameters.output_parameter.value); // output value 

    // ... 
}); 
0

根据节点MSSQL文件(我已经通过这一切走了,相信我),记录或记录集是一组返回,当你执行选择查询。 由于您正在执行插入查询,因此很可能未定义。因为即使记录已被退回,这将是一整套(包括你的新插入的行),这是不是在插入:)

总之是非常有用的,如果您的查询不包含选择,你”会得到未定义的记录集。 希望这有助于。

+0

你说得对,刚才发现我们需要指定要使用OUTPUT子句返回的记录。感谢您的回答。 –