ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
333 stars 133 forks source link

error: 'free_row_buffer' was not declared in this scope #167

Open yasar-git opened 3 years ago

yasar-git commented 3 years ago

I am trying to get database data from 30 tables every 10 seconds. I used your code It works fine. But I couldn't use the free_row_buffer() methods. It ends up in error: 'free_row_buffer' was not declared in this scope. If I remove that function call, the sketch works fine for a while and becoming unstable (not getting data from the database). Must be a memory leak (as explained in that link). Why I couldn't use free_row_buffer() and free_columns_buffer() calls ? Is it a problem with mariadb version ? (mine is 10.3.13)

ChuckBell commented 3 years ago

That is correct. The free* methods are private, but you can make them public by moving them above the public declaration in MySQL_Cursor.h. Easy change. Not an issue with MySQL.

Also, be aware that unless you're using a board with a lot (relatively) of memory, you are likely to encounter problems trying to perform a lot of queries. It is possible you could run low on memory and cause strange behavior. I would also suggest looking through the wiki for tips such as opening and closing the connection through each pass of the loop() method, reducing memory usage, etc.

That said, the connector is not guaranteed to work on non-Oracle variants of MySQL. If you encounter problems with your MySQL installation, you're on your own there, sorry.

yasar-git commented 3 years ago

I changed my DB to Oracle db. But the problem is, if I put all the code to do SELECT inside a function and call the function inside the void loop, it always returns NULL. That's strange. But if the code is inside void loop, it returns values. Why is it happening test ?

yasar-git commented 3 years ago
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

// IP and other details here-

int device_id = 1;
String Parameter[3] = {"one", "two", "three"};                            // aim is to update these values

EthernetClient client;
MySQL_Connection conn((Client *)&client);

const char QUERY_PARA[] = "SELECT ref_time, val_first, val_second  FROM test_db.test_table WHERE Id=  %lu;";
char query[128];

void setup()
{
    Serial.begin(115200);
    while (!Serial);
    Ethernet.begin(mac_addr);   
}

void loop()
{
    Serial.println("inside the loop....");
    delay(10000);
    check_parameter();
}

void check_parameter()
{
  if (conn.connect(server_addr, 3306, user, password))
    {
        Serial.println("calling the check_para....");
        delay(5000); 

        MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
        sprintf(query, QUERY_PARA, device_id);

        cur_mem->execute(query);
        column_names *cols = cur_mem->get_columns();

        Serial.println();
        row_values *row = NULL;

        do
        {
            row = cur_mem->get_next_row();
            if (row != NULL)
            {
              // here is the problem. the row is always NULL! I dunno why ??

                Parameter[0] = String(row->values[0]);
                Parameter[1] = String(row->values[1]);
                Parameter[2] = String(row->values[2]);

                cur_mem->free_row_buffer();
            }else
            {
              Serial.println("Empty Returns! But why");
            }

        } while (row != NULL);
        cur_mem->free_columns_buffer();
        delete cur_mem;

        Serial.println("printing parameters");
        Serial.println(Parameter[0]);
        Serial.println(Parameter[1]);
        Serial.println(Parameter[2]);

        conn.close();
    }
    else
    {
        Serial.println("Connection failed.");
    }   
}
acgiese commented 2 years ago

That is correct. The free* methods are private, but you can make them public by moving them above the public declaration in MySQL_Cursor.h. Easy change. Not an issue with MySQL.

Also, be aware that unless you're using a board with a lot (relatively) of memory, you are likely to encounter problems trying to perform a lot of queries. It is possible you could run low on memory and cause strange behavior. I would also suggest looking through the wiki for tips such as opening and closing the connection through each pass of the loop() method, reducing memory usage, etc.

That said, the connector is not guaranteed to work on non-Oracle variants of MySQL. If you encounter problems with your MySQL installation, you're on your own there, sorry.

Dear Chuck, I tried but this suggestion you gave didn't work. If not asking too much, can you please post here an exemple or give another alternative? I appreciate so much. Tks (acgiese@gmail.com)

ChuckBell commented 2 years ago

Most likely it is your format string: "SELECT ref_time, val_first, val_second FROM test_db.test_table WHERE Id= %lu;". Try changing it to "SELECT ref_time, val_first, val_second FROM test_db.test_table WHERE Id=%d;". To double-check, connect to MySQL with the mysql client and issue the query: "SELECT ref_time, val_first, val_second FROM test_db.test_table WHERE Id=1;", You should see some results in the client iff there are rows that match id=1.

acgiese commented 2 years ago

Tks a lot for your answer. I'll try your suggestion. Alan Giese

Em qui., 23 de set. de 2021 às 22:21, Dr. Charles Bell < @.***> escreveu:

Most likely it is your format string: "SELECT ref_time, val_first, val_second FROM test_db.test_table WHERE Id= %lu;". Try changing it to "SELECT ref_time, val_first, val_second FROM test_db.test_table WHERE Id=%d;". To double-check, connect to MySQL with the mysql client and issue the query: "SELECT ref_time, val_first, val_second FROM test_db.test_table WHERE Id=1;", You should see some results in the client iff there are rows that match id=1.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/167#issuecomment-926275321, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQJRMW6LYXWJ3KVBZM32XILUDPHBTANCNFSM42BLV4BA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.