Search code examples
sqljsondb2ibm-cloudnode-red

Bluemix SQLDB Query - Can't figure out JSON Parameter Markings


In my Nodered Bluemix application, I'm trying to make a SqlDB query, but I can't find sufficient documentation or examples on how to use the parameter markings in the query. Are there any examples and further insight into what I am doing wrong? Here is the flow I am having trouble with:

[
    {       
        "id":"7924a83a.03355",
        "type":"websocket-listener",
        "path":"/ws/dbdata",
        "wholemsg":"false"
    },
    {
        "id":"b84efad2.9a2a58",
        "type":"function",
        "name":"Parse JSON",
        "func":"msg.payload = JSON.parse(msg.payload);\nvar begin = msg.payload[0].split(\" \");\nbegin[1] = begin[1]+\":00\";\nvar date1 = begin[0].split(\"-\");\nvar processStart = date1[2]+\"-\"+date1[0]+\"-\"+date1[1]+\" \"+begin[1];\n\nvar end = msg.payload[0].split(\" \");\nend[1] = end[1]+\":00\";\nvar date2 = end[0].split(\"-\");\nvar processEnd = date2[2]+\"-\"+date2[0]+\"-\"+date2[1]+\" \"+end[1];\n\nmsg.payload[0] = processStart;\nmsg.payload[1] = processEnd;\nreturn msg;",
        "outputs":1,"noerr":0,"x":381.79998779296875,"y":164.8000030517578,"z":"3f9da5d2.b3f0aa",
        "wires":[["4f92b16a.cf981"]]
    },
    {
        "id":"3e20f8a4.06451",
        "type":"websocket in",
        "name":"dbInput",
        "server":"7924a83a.03355",
        "client":"",
        "x":159.8000030517578,"y":164.8000030517578,"z":"3f9da5d2.b3f0aa",
        "wires":[["b84efad2.9a2a58"]]
    },
    {
        "id":"68a4a35.5983f5c",
        "type":"debug",
        "name":"",
        "active":true,"console":"false",
        "complete":"true",
        "x":970.7999877929688,"y":162.8000030517578,"z":"3f9da5d2.b3f0aa",
        "wires":[]
    },
    {
        "id":"5a0aed1c.34279c",
        "type":"sqldb in",
        "service":"LabSensors-sqldb",
        "query":"",
        "params":"{msg.begin},{msg.end}",
        "name":"db Request",
        "x":787.7999877929688,"y":163.8000030517578,"z":"3f9da5d2.b3f0aa",
        "wires":[["68a4a35.5983f5c"]]
    },
    {
        "id":"e08c4a85.e95e68",
        "type":"debug",
        "name":"",
        "active":true,"console":"false",
        "complete":"true",
        "x":791.7999877929688,"y":233.8000030517578,"z":"3f9da5d2.b3f0aa",
        "wires":[]
    },
    {
        "id":"4f92b16a.cf981",
        "type":"function",
        "name":"Construct Query",
        "func":"msg.begin = msg.payload[0];\nmsg.end = msg.payload[1];\nmsg.payload = \"SELECT * FROM IOT WHERE TIME >= '?' AND TIME < '?'\";\nreturn msg;",
        "outputs":1,"noerr":0,"x":583.7999877929688,"y":163.8000030517578,"z":"3f9da5d2.b3f0aa",
        "wires":[["5a0aed1c.34279c",
        "e08c4a85.e95e68"]]
    }
]

Solution

  • In the node-red documentation for the SQLDB query node it says:

    "Parameter Markers is a comma delimited set of json paths. These will replace any question marks that you place in your query, in the order that they appear."

    Have you tried removing the curly braces, i.e. to set the "params" field in the node to just "msg.begin,msg.end"?