Read data from databse and store into a variables.

Hello.

I have a question about read MySql tables.

I the sample code, move the data from the database with the follow instruction


// Read the rows and print them
row_values *row = NULL;
long head_count = 0;
do
{
row = cur_mem->get_next_row();
if (row != NULL)
{
Serial.print(row->values[1]);
head_count = atolr(row->values[1]);
}
} while (row != NULL);


In this case, use atol() method to help store the array value into the head_count variable.

This method only work with numeric data. That correct?

The value that I need to store into head_count variable came from the dtabase and is the letter “A”.

What is the counterpart of the method atol() to store the character data into the same varaible.

The sample is in the page 19 under Complex Select title, of the document that I include in this post.

Thank you in advance for the help.

Regards.

MySQL_Connector_Arduino_Reference_Manual.pdf (389 KB)

This method only work with numeric data. That correct?

The atol() method converts a string that contains the representation of an integral value to a long.

No clue what that function in your useless snippet actually does.

The value that I need to store into head_count variable came from the dtabase and is the letter "A".

Well that would be stupid. Who counts 'A', 'B', 'C'?

What is the counterpart of the method atol() to store the character data into the same varaible.

There is no function to convert 'A' to an integral value meaningfully.

your example suggests that get_next_row returns an array of strings so there is no need for a function to grab a single letter, you can just assign it directly:

 // Read the rows and print them
  row_values *row = NULL;
  char ch;
  do
  {
    row = cur_mem->get_next_row();
    if (row != NULL)
    {
      Serial.print(row->values[1]);
      ch = row->values[1][0]; 
    }
  } while (row != NULL);

Hi wildbill

thanks for thw answert. It work.

Bye