ChuckBell / MySQL_Connector_Arduino

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

Help with select #110

Closed sidneysamir closed 4 years ago

sidneysamir commented 5 years ago

Hi Dr. ChuckBell!

I am trying to check if a value exists on a table with the format below.

Item | Code | Date

1 | Samir | Date1 2 | Chaves| Date2

The query that I am using is: char query[] = "SELECT Item FROM bdardui.Tab1 WHERE Code= 'Chaves'";

I am trying to get the value from the column item with this code:

void VerificarValor(){

row_values *row = NULL; int head_count = 0;

MySQL_Cursor cur_mem = new MySQL_Cursor(&conn); // Execute the query cur_mem->execute(query); // Fetch the columns (required) but we don't use them. column_names columns = cur_mem->get_columns(); // Read the row (we are only expecting the one) do { row = cur_mem->get_next_row(); if (row != NULL) { head_count = atol(row->values[0]); } } while (row != NULL); // Deleting the cursor also frees up memory used cur_mem->close(); delete cur_mem;

Serial.print(" Resultado = "); Serial.println(head_count);
}

But the result I am having is "Resultado= 0" (What I need is the value of the column Item when the column Code has "Chaves". Can you help me?

ChuckBell commented 5 years ago

Ok, here's a possible fix.

int MySQL_Packet::wait_for_bytes(int bytes_need) { const long wait_till = millis() + MYSQL_DATA_TIMEOUT; int num = 0; long now = 0;

do { now = millis(); num += client->available();

Change that last line in the code above (MySQL_Packet.cpp) - add + before the =. Let me know if it works.

sidneysamir commented 5 years ago

I did it and saved the file, unfortunatelly after run the code again I am having the issue yet.

image

ChuckBell commented 5 years ago

I ran your code unchanged and it worked for me with this change on 5.6 and without it on 8.0. I’m thinking permissions still.

On Tue, Aug 20, 2019 at 11:55 Sidney Samir notifications@github.com wrote:

I did it and saved the file, unfortunatelly after run the code again I am having the issue yet.

[image: image] https://user-images.githubusercontent.com/39540097/63363244-a3d22d00-c349-11e9-9ad1-c5c971ba8a27.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/110?email_source=notifications&email_token=AB6SHYAICE6NRY5IIYVDNG3QFQHWXA5CNFSM4IL233Y2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4WYZMQ#issuecomment-523078834, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6SHYHNWZ4D4OOOGGEE643QFQHWXANCNFSM4IL233YQ .

sidneysamir commented 4 years ago

Doctor Charles, your support was wonderful!

The problem was solved!!! Thank you very much for your attention.