简体   繁体   English

使用节点red和bluemix更新sqldb中的列

[英]update a column in sqldb using node red and bluemix

I am using Node-RED to insert information into the included sqldb. 我正在使用Node-RED将信息插入到包含的sqldb中。

I am successful at entering the data but I can't seem to update it. 我可以成功输入数据,但似乎无法更新。 I am unsure of the syntax. 我不确定语法。 The table is called ITEMS and there are 2 columns ID and ITEMS . 该表称为ITEMS,并且有2列IDITEMS I want to keep updating the first element. 我想继续更新第一个元素。 Any suggestions of why this is not working? 为什么这不起作用的任何建议?

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

It looks like your update query is 看来您的更新查询是

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

There doesn't seam to be a test for the WHERE ID value to limit the update to the right row. 没有缝隙可以测试WHERE ID值以将更新限制在右行。 And do you actually need to reset the ID value? 并且您实际上是否需要重置ID值?

Something more like this would be what I'd expect 我更希望这样的事情

UPDATE ITEMS SET ITEM = ? WHERE ID = 1; 

And the msg.payload should be in the Parameter Markers field. 并且msg.payload应该在“ 参数标记”字段中。

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

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