0

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

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

[
  {
    "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"
      ]
    ]
  }
]
4

1 回答 1

1

看起来您的更新查询是

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

没有接缝测试该WHERE ID值以将更新限制在正确的行。你真的需要重置 ID 值吗?

更像这样的事情将是我所期望的

UPDATE ITEMS SET ITEM = ? WHERE ID = 1; 

并且 msg.payload 应该在Parameter Markers字段中。

于 2016-02-17T20:56:52.150 回答