What do I want to achieve?
Call a variable inside an UPDATE QUERY
I will explain you what do I have
We have a table called Despacho
We want to UPDATE a value
I have a SELECT query -> SELECT IDDESPACHO FROM Pruebas_DB.Despacho in which is stored in a variable called CHAR SELECT[];
and I want to use that variable "CHAR SELECT[]" inside of another query (UPDATE QUERY to be more specific)
which is the next one:
char UPDATE_DATA[] = "UPDATE Pruebas_DB.Despacho SET Litros_Despachados = %s WHERE IDDESPACHO = "(Variable CHAR SELECT[] that I dont know how to make a reference)";
What does update_data[] do?
Update a column value called Litros_Despachados
and then the issue is in the condition
when I want to compare in this case the IDDESPACHO with the variable CHAR SELECT[] that I mentioned
at the first paragraph
I dont know how to call it inside the update query and execute it.
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
//DB DATA
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr( 0, 0, 0, 0); // IP of the MySQL *server* here
char user[] = "user"; // MySQL user login username
char password[] = "password"; // MySQL user login password
//DB CONNECTION
EthernetClient client;
MySQL_Connection conn((Client *)&client);
void loop(){
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
char SELECT[]="SELECT IDDESPACHO FROM Pruebas_DB.Despacho order by cont desc limit 1";
char selectstore[20];
char INSERT_DATA[] = "UPDATE Pruebas_DB.Despacho SET Litros_Despachados = %s WHERE IDDESPACHO = SELECT[] ";
cur_mem->execute(query);
delete cur_mem;
conn.close();
Serial.println("Update");
}