EDG
EDG

Reputation: 41

How to pass a null value received on msg.req.query to msg.payload

I am developing an application using Dashdb on Bluemix and nodered, my PHP application uses the call to webservice to invoke the node-red, whenever my function on PHP invokes the node to insert on table and the field GEO_ID is null, the application fails, I understand the issue, it seems the third parameter was not informed, I have just tried to check the param before and passing something like NULL but it continues not working.

See the code:

msg.account_id = msg.req.query.account_id;
msg.user_id = msg.req.query.user_id;
msg.geo_id=msg.req.query.geo_id;
msg.payload = "INSERT INTO ACCOUNT_USER (ACCOUNT_ID, USER_ID, GEO_ID) VALUES (?,?,?) ";
return msg;

And on Dashdb component I have set the parameter as below:

msg.account_id,msg.user_id,msg.geo_id

The third geo_id is the issue, I have tried something like the code below:

if(msg.req.query.geo_id===null){msg.geo_id=null}

or

if(msg.req.query.geo_id===null){msg.geo_id="null"}

The error I got is the one below:

dashDB query node: Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0420N Invalid character found in a character string argument of the function "DECIMAL". SQLSTATE=22018

I really appreciate if someone could help me on it . Thanks, Eduardo Diogo Garcia

Upvotes: 0

Views: 687

Answers (1)

markwatsonatx
markwatsonatx

Reputation: 3491

Is it possible that msg.req.query.geo_id is set to an empty string?

In that case neither if statement above would get executed, and you would be trying to insert an empty string into a DECIMAL column. Maybe try something like this:

if (! msg.req.query.geo_id || msg.req.query.geo_id == '') {
   msg.geo_id = null;
}

Upvotes: 1

Related Questions