使用节点red和bluemix

时间:2016-02-17 18:44:06

标签: ibm-cloud node-red sqldb

我正在使用Node-RED将信息插入到包含的sqldb中。

我成功输入数据,但似乎无法更新数据。我不确定语法。该表名为 ITEMS ,有2列 ID ITEMS 。我想继续更新第一个元素。为什么这不起作用的任何建议?

[
  {
    "id": "6ba3d5df.945c2c",
    "type": "sqldb out",
    "z": "ed26e4d5.12d918",
    "service": "SQL Database-kr",
    "table": "ITEMS",
    "name": "",
    "x": 571,
    "y": 167,
    "wires": []
  },
  {
    "id": "fb5a8388.04a58",
    "type": "inject",
    "z": "ed26e4d5.12d918",
    "name": "",
    "topic": "ITEM",
    "payload": "andy",
    "payloadType": "str",
    "repeat": "60",
    "crontab": "",
    "once": false,
    "x": 142,
    "y": 218,
    "wires": [
      [
        "caaf691d.355098",
        "94b0c839.6b4f38"
      ]
    ]
  },
  {
    "id": "94b0c839.6b4f38",
    "type": "debug",
    "z": "ed26e4d5.12d918",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "payload",
    "x": 588,
    "y": 253,
    "wires": []
  },
  {
    "id": "caaf691d.355098",
    "type": "sqldb in",
    "z": "ed26e4d5.12d918",
    "service": "SQL Database-kr",
    "query": "UPDATE ITEMS \nSET ID = 1,ITEM = msg.payload,\nWHERE ID; ",
    "params": "",
    "name": "",
    "x": 405.5,
    "y": 287,
    "wires": [
      [
        "94b0c839.6b4f38"
      ]
    ]
  },
  {
    "id": "70a9564.f8f56a8",
    "type": "inject",
    "z": "ed26e4d5.12d918",
    "name": "",
    "topic": "",
    "payload": "andrew",
    "payloadType": "str",
    "repeat": "",
    "crontab": "",
    "once": true,
    "x": 206.5,
    "y": 176,
    "wires": [
      [
        "88cf0713.7730f8"
      ]
    ]
  },
  {
    "id": "88cf0713.7730f8",
    "type": "function",
    "z": "ed26e4d5.12d918",
    "name": "",
    "func": "msg.payload =\n{\n   ID: 1,\n   ITEM : msg.payload,\n}\nreturn msg;\n",
    "outputs": 1,
    "noerr": 0,
    "x": 429.5,
    "y": 171,
    "wires": [
      [
        "6ba3d5df.945c2c"
      ]
    ]
  }
]

1 个答案:

答案 0 :(得分:1)

您的更新查询似乎是

UPDATE ITEMS SET ID = 1,ITEM = msg.payload WHERE ID; 

没有接缝是WHERE ID值的测试,以限制更新到右行。你真的需要重置ID值吗?

更像这样的东西就是我所期待的

UPDATE ITEMS SET ITEM = ? WHERE ID = 1; 

msg.payload应该在参数标记字段中。