3

我正在尝试将两个参数传递给来自 Bluemix 上 Node-Red 流编辑器中的 dashDB 对象的 sql 查询。我的参数存储在 msg.fromDate 和 msg.toDate 中,我想将它们输入到 dashDB 节点的“参数标记”中。当我只使用一个参数时,我只需在参数标记中键入“msg.fromDate” ,它就可以正常工作。在日志中我看到了这个:

2015-12-10T12:22:12.856+0100 [App/0] out 输入节点:pathToArray: msg,toDate 2015-12-10T12:22:12.856+0100 [App/0] out 输入节点:parameterValues: 2015-12 -01

现在,当我尝试使用两个输入参数时,我在“参数标记”中键入“msg.toDate,msg.fromDate”,我在日志中收到此错误:

2015-12-10T12:26:01.271+0100 [App/0] 出 12 月 10 日 11:26:01 - [错误] [dashDB in:流行词] TypeError:无法读取未定义的属性“fromDate”

2015-12-10T12:26:01.270+0100 [App/0] out 输入节点:pathToArray: msg,toDate, msg,fromDate

如何传递两个参数?

4

2 回答 2

3

我找到了这个问题的原因。看起来当我像这样输入“参数标记”时:

msg.toDate, msg.fromDate

这没用。像这样它可以工作:

msg.toDate,msg.fromDate

换句话说,参数之间的空间会破坏它!

于 2015-12-11T14:05:28.087 回答
1

您不能在参数之间使用引号,不确定您是否添加引号只是为了格式化您的任务或实际将其添加到您的参数中。

我编写了一个简单的节点红色流程function node来构建查询及其dashDB node本身。

在我的function node我有以下查询:

msg.fromDate = '2011-04-12 00:00:00';
msg.toDate= '2015-03-12 00:00:00';
msg.payload = "SELECT COL2 FROM DASH104951.TESTDATE WHERE START >= ? AND END <= ?";
return msg;

dashDB node我只有参数标记文本字段:

msg.fromDate,msg.toDate

一切正常。

这是我的 node-red 流程,如果您想将其导入您自己的 node-red 应用程序:

[{"id":"211a834b.dee57c","type":"inject","z":"197f318.fe680ce","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":117,"y":115,"wires":[["7a23c994.85dc38"]]},{"id":"7a23c994.85dc38","type":"function","z":"197f318.fe680ce","name":"Build Query","func":"msg.fromDate = '2011-04-12 00:00:00';\nmsg.toDate= '2015-03-12 00:00:00';\nmsg.payload = \"SELECT COL2 FROM DASH104951.TESTDATE WHERE START >= ? AND END <= ?\";\nreturn msg;","outputs":1,"noerr":0,"x":325,"y":123,"wires":[["559c92e4.aa636c"]]},{"id":"24974090.db68c","type":"debug","z":"197f318.fe680ce","name":"dashDB query result","active":true,"console":"false","complete":"true","x":773,"y":125,"wires":[]},{"id":"559c92e4.aa636c","type":"dashDB in","z":"197f318.fe680ce","service":"dashDB-0a","query":"","params":"msg.fromDate,msg.toDate","name":"","x":548,"y":131,"wires":[["24974090.db68c"]]}]
于 2015-12-11T03:04:34.853 回答