/** * show_results - Show a result set from the server via Serial.print * * This method reads a result from the server and displays it via the * via the Serial.print methods. It can be used in cases where * you may want to issue a SELECT or SHOW and see the results on your * computer from the Arduino. * * It is also a good example of how to read a result set from the * because it uses the public methods designed to return result * sets from the server. */ void Connector::show_results() { column_names *cols; int rows = 0; // Get the columns cols = get_columns(); if (cols == NULL) { return; } for (int f = 0; f < columns.num_fields; f++) { Serial.print(columns.fields[f]->name); if (f < columns.num_fields-1) Serial.print(','); } Serial.println(); // Read the rows while (get_next_row()) { rows++; for (int f = 0; f < columns.num_fields; f++) { Serial.print(row.values[f]); if (f < columns.num_fields-1) Serial.print(','); } free_row_buffer(); Serial.println(); } // Report how many rows were read Serial.print(rows); Serial.println(" rows in result."); free_columns_buffer(); }
/* get_columns - Get a list of the columns (fields) This method returns an instance of the column_names structure that contains an array of fields. Note: you should call free_columns_buffer() after consuming the field data to free memory. */ column_names *MySQL_Cursor::get_columns() { free_columns_buffer(); free_row_buffer(); num_cols = 0; if (get_fields()) { columns_read = true; return &columns; } else { return NULL; } }
/* show_results - Show a result set from the server via Serial.print This method reads a result from the server and displays it via the via the Serial.print methods. It can be used in cases where you may want to issue a SELECT or SHOW and see the results on your computer from the Arduino. It is also a good example of how to read a result set from the because it uses the public methods designed to return result sets from the server. */ void MySQL_Cursor::show_results() { column_names *cols; int rows = 0; // Get the columns cols = get_columns(); if (cols == NULL) { return; } for (int f = 0; f < columns.num_fields; f++) { Serial.print(columns.fields[f]->name); if (f < columns.num_fields-1) Serial.print(','); } Serial.println(); // Read the rows while (get_next_row()) { rows++; for (int f = 0; f < columns.num_fields; f++) { Serial.print(row.values[f]); if (f < columns.num_fields-1) Serial.print(','); } free_row_buffer(); Serial.println(); } // Report how many rows were read Serial.print(rows); conn->show_error(ROWS, true); free_columns_buffer(); // Free any post-query messages in queue for stored procedures clear_ok_packet(); }
/* Close Takes care of removing allocated memory. */ void MySQL_Cursor::close() { free_columns_buffer(); free_row_buffer(); }