简体   繁体   中英

update a column in sqldb using node red and bluemix

I am using Node-RED to insert information into the included 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 . 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. And do you actually need to reset the ID value?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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