Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-484

cant pass float var in insert statement

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Not a Bug
    • Affects Version/s: 3.1.9
    • Fix Version/s: N/A
    • Component/s: None
    • Labels:
      None
    • Environment:
      raspianos GNU/Linux 10 on Raspberry pi 4a

      Description

      #include <mariadb/mysql.h>
      .
      .
      .
      float pHReading, TempReading;
      .
      .
      .
      if( tab_reg[0] > 64500 )
      pHReading = ( (float)tab_reg[0] - 65535 ) / 100;
      else
      pHReading = (float)tab_reg[0] / 100;
      printf( "Register 43001 pH = %.2f\n", pHReading );
      .
      .
      .
      TempReading = (float)(tab_reg[0])/10;
      .
      .
      .
      query = "insert into pHTemp values( NULL, NOW(), pHReading, TempReading )";
      printf( "pHReading: %f and TempReading: %f and QUERY: %s\n", pHReading, TempReading, query );
      if (mysql_real_query(mysql, query, strlen(query)))
      show_error(mysql);

      The resulting output and error are:
      pHReading: 3.500000 and TempReading: 24.600000 and QUERY: insert into pHTemp values( NULL, NOW(), pHReading, TempReading )
      Error(1054) [42S22] "Unknown column 'pHReading' in 'field list'"root@PiDevel:~/ModBus#

      I cant seem to get the float vars pHReading and TempReading to dereference in the query before sending them to the DB

      What am I doing wrong???

      Richard

        Attachments

          Activity

            People

            Assignee:
            georg Georg Richter
            Reporter:
            gdlwyverex Richard Couture
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration