Completly new to Node Red (latest version, just installed) but understand the working. It's a nice development environment but one can get vague error messages Like this one:
"Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DHT_C_Sensor' at line 1"
I've looked over end over and cannot find a clue. The function is quite simple
var dataArray = msg.payload.split(";");
var itype = dataArray[1];
var ihum = dataArray[2];
var itemp = dataArray[3];
var ihic = dataArray[4];
var irsrp = dataArray[5];
msg.payload = dataArray;
var msgDB = {};
msgDB.topic = "insert into DHT(Type,Hum,Temp,Hic,rsrp) values(?,?,?,?,?);"
msgDB.payload = [itype, ihum, itemp, ihic, irsrp];
I manually created the SQL string and executed it and there was no problem.
The DataBase exist, the table exist, the connections are OK
Thank you, it solved the problem!!
To be quite honest, I copied (stolen/borrowed) the code. So my task for today: crash course Node Red! Really appriciate the help, thought coud do the quick route
Ps Colin,
The debug 4 - Output Complete Message didn't give me more logical information. But good to know to set this on in case of ...
2/5/2025, 7:17:16 AMnode: debug 4
DHT_C_Sensor : msg : Object
object
topic: "DHT_C_Sensor"
payload: array[6]
0: "DHT01"
1: "C"
2: " 53.50"
3: "16.50"
4: "15.60"
5: " 123"
qos: 1
retain: false
_msgid: "ad43d54196eee62f"
2/5/2025, 7:17:16 AMnode: DHT
msg : error
"Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DHT_C_Sensor' at line 1"
Your SQL statement is a "prepared query" which is good form, it protects the database from SQL injection (I've learned that by rote, no idea how it actually works).
I personally avoid the ?, ?, ?, ... syntax, preferring a prepared query with msg.payload as explicit key: value pairs.