ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
331 stars 132 forks source link

stored procedure bad mojo. EOF found reading column header #83

Closed Glammies closed 2 years ago

Glammies commented 5 years ago

hi everyone

i need use one stored procedure on arduino because i need managing device from DB .when i read a normal table works perfect but when i try execute one stored procedure the device start rebooting after firts reading. you can check on the picture i can read once i am using one nodemcu.

below i past my code and some printscreens

thanks for your help sorry my english


include

include

include

// WiFi card example const char ssid = "jhsdbsd"; const char Wpassword = "asfasfasf";

//dados conecção MYSQL IPAddress server_addr(192,168,1,21); // IP of the MySQL server here char user[] = "gsafsafasfs"; // MySQL user login username char password[] = "Asfafafas"; // MySQL user login password

WiFiClient client; MySQL_Connection conn((Client *)&client); MySQL_Cursor cur = MySQL_Cursor(&conn);

//const char QUERY_POP[] = "SELECT Schedule.idSchedule,Schedule.Jardim_idJardim,Schedule.Hora_Inicio,Schedule.On_Time,Schedule.Frequencia,Schedule.EnableFROM Rega_Auto.Schedule;SELECT * FROM Rega_Auto.Schedule;"; const char QUERY_POP[] = "CALL Rega_Auto.schedule_rega();"; char query[128]; //char query[] = "CALL Rega_Auto.schedule_rega();"; void setup() { Serial.begin(115200); WiFi.hostname("RegaJardim"); WiFi.mode(WIFI_STA); WiFi.begin(ssid, Wpassword);

Serial.printf("Connecting to %s ", ssid);

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("wireless connected ");

Serial.println("Connecting to database...");

if (conn.connect(server_addr, 3306, user, password)) 
{
  delay(1000);
}
else
{
  Serial.println("Connection failed.");
  conn.close();
}

}

void loop() { delay(1000);

Serial.println("> Running SELECT with dynamically supplied parameter");

// Initiate the query class instance MySQL_Cursor cur_mem = new MySQL_Cursor(&conn); // Supply the parameter for the query // Here we use the QUERY_POP as the format string and query as the // destination. This uses twice the memory so another option would be // to allocate one buffer for all formatted queries or allocate the // memory as needed (just make sure you allocate enough memory and // free it when you're done!). sprintf(query, QUERY_POP, 9000000); // Execute the query cur_mem->execute(query); // Fetch the columns and print them column_names cols = cur_mem->get_columns(); for (int f = 0; f < cols->num_fields; f++) { Serial.print(cols->fields[f]->name); if (f < cols->num_fields-1) { Serial.print(','); } } Serial.println(); // Read the rows and print them row_values *row = NULL; do { row = cur_mem->get_next_row(); if (row != NULL) { for (int f = 0; f < cols->num_fields; f++) { Serial.print(row->values[f]); if (f < cols->num_fields-1) { Serial.print(','); } } Serial.println(); } } while (row != NULL); // Deleting the cursor also frees up memory used delete cur_mem; }


mysql serial

ChuckBell commented 5 years ago

Hi. I’m sorry, but the connector does not support variants of MySQL. Please install Oracle’s MySQL and try again. If you have problems still, we can try to sort it. In the meantime, please post your stored procedure and I’ll try to see if there are any issues there. If your stored procedure doesn’t return rows, that could be the problem. But again, the connector does not support the MySQL variant you’re using. So it could be yet another incompatibility.

On Jan 31, 2019, at 5:47 PM, Glammies notifications@github.com wrote:

hi everyone

i need use one stored procedure on arduino because i need managing device from DB .when i read a normal table works perfect but when i try execute one stored procedure the device start rebooting after firts reading. you can check on the picture i can read once i am using one nodemcu.

below i past my code and some printscreens

thanks for your help sorry my english

include

include

include

// WiFi card example const char ssid = "jhsdbsd"; const char Wpassword = "asfasfasf";

//dados conecção MYSQL IPAddress server_addr(192,168,1,21); // IP of the MySQL server here char user[] = "gsafsafasfs"; // MySQL user login username char password[] = "Asfafafas"; // MySQL user login password

WiFiClient client; MySQL_Connection conn((Client *)&client); MySQL_Cursor cur = MySQL_Cursor(&conn);

//const char QUERY_POP[] = "SELECT Schedule.idSchedule,Schedule.Jardim_idJardim,Schedule.Hora_Inicio,Schedule.On_Time,Schedule.Frequencia,Schedule.EnableFROM Rega_Auto.Schedule;SELECT * FROM Rega_Auto.Schedule;"; const char QUERY_POP[] = "CALL Rega_Auto.schedule_rega();"; char query[128]; //char query[] = "CALL Rega_Auto.schedule_rega();"; void setup() { Serial.begin(115200); WiFi.hostname("RegaJardim"); WiFi.mode(WIFI_STA); WiFi.begin(ssid, Wpassword);

Serial.printf("Connecting to %s ", ssid);

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("wireless connected ");

Serial.println("Connecting to database...");

if (conn.connect(server_addr, 3306, user, password)) { delay(1000); } else { Serial.println("Connection failed."); conn.close(); } }

void loop() { delay(1000);

Serial.println("> Running SELECT with dynamically supplied parameter");

// Initiate the query class instance MySQL_Cursor cur_mem = new MySQL_Cursor(&conn); // Supply the parameter for the query // Here we use the QUERY_POP as the format string and query as the // destination. This uses twice the memory so another option would be // to allocate one buffer for all formatted queries or allocate the // memory as needed (just make sure you allocate enough memory and // free it when you're done!). sprintf(query, QUERY_POP, 9000000); // Execute the query cur_mem->execute(query); // Fetch the columns and print them column_names cols = cur_mem->get_columns(); for (int f = 0; f < cols->num_fields; f++) { Serial.print(cols->fields[f]->name); if (f < cols->num_fields-1) { Serial.print(','); } } Serial.println(); // Read the rows and print them row_values *row = NULL; do { row = cur_mem->get_next_row(); if (row != NULL) { for (int f = 0; f < cols->num_fields; f++) { Serial.print(row->values[f]); if (f < cols->num_fields-1) { Serial.print(','); } } Serial.println(); } } while (row != NULL); // Deleting the cursor also frees up memory used delete cur_mem; }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Glammies commented 5 years ago

thanks for your help. I am using on raspberry 1 with mariaDB for database. I create this S.P. just for test. Please verify if you see any problem. I will install mysql and try again


CREATE DEFINER=glammies@% PROCEDURE test() BEGIN

DECLARE Turn_on_device int DEFAULT 0; DECLARE Turn_on_device2 int DEFAULT 0;

Set Turn_on_device=100; Set Turn_on_device2 =99; SELECT Turn_on_device as Turn_on_device, Turn_on_device2 as Turn_on_device2 ;

END