I have some questions relating database

can you show me example?

8/22/2018, 2:39:58 AMnode: e2f3b3a4.fb279SELECT * FROM tab WHERE name LIKE '10' : msg : Object

object

_msgid: "cf4fc734.30b038"

topic: "SELECT * FROM tab WHERE name LIKE '10'"

payload: array[1]

0: object

ID: 1001

name: "10"

surname: "11"

time: "2018-08-20T23:08:37.000Z"

(put three back tic's before and after the information you paste in from the debug node)

Ok, hat looks like tthe debug from a select that returns data, now what about the other case?

When you say LIKE '11' what exactly are you hoping that will give you?
Have a look at SQLite LIKE - Querying Data Based On Pattern Matching to see the usual way LIKE is used.
If you are looking for name = '11' then normally one would use
msg.topic= "SELECT * FROM tab WHERE name = '11'";

thanks for the information
but now want to send to debug (yes) if found 11 and if not found 11 want to send (no) to debug
can you tell me how to do it?

Once again I will ask you: what do you see in the debug output when you:

  1. Find the a row and
  2. when you don't don't find the row?

Once you have the debug outputs, ou should be able to see a difference and use a switch node to test for them.

image

Please go back and read the previous post and answer all the questions

what question you want answer for?
I sent picture to you in the previous post

@zenofmud asked questions which he helpfully labelled 1 and 2. Since you only provided one answer I deduce that you have not answered both questions.

1 Like

soory, forget to send another picture
note : debug set to (complete msg object)
please check both pictures

image
image

So now you have to work out what the key difference in payload is so you can use a Switch node to differentiate.

@zenofmud @Colin I do not know how to do it because I am new to use node red it is appreciated if you tell me what is expression can do to send (yes) if the data is exist and and (no) if the data not exist

What do you see in the debug messages that is different? Look at each piece of the msg.

dear, I see the difference but do not know how to do it
could you please give me example?

take a look at the 'switch' node and see if that will help you.

@zenofmud

if data exist :

msg.payload : string[74]

"[{"ID":1001,"name":"10","surname":"11","time":"2018-08-20T23:08:37.000Z"}]"

if data not exist then this :

[]

this is the message so what to do next?

Use a switch node to test what you have found

The payload isn't a string if the message exists, it is an array of length 1. If there were multiple matching records then there would be one element for each record.
However, since all you are interested in is whether a record exists or not I think you would be better using the query
SELECT count(*) FROM tab WHERE name='16'
which will tell you how many matching records there are and you can then test the result for zero or non-zero in a Switch node.

1 Like

I want to get value from mqtt and insert inside variable (check) then
msg.topic= "SELECT * FROM tab WHERE name = 'check'";

but it is not working