[CONC-484] cant pass float var in insert statement Created: 2020-07-13  Updated: 2023-12-06  Resolved: 2020-07-13

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: 3.1.9
Fix Version/s: N/A

Type: New Feature Priority: Major
Reporter: Richard Couture Assignee: Georg Richter
Resolution: Not a Bug Votes: 0
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



 Comments   
Comment by Richard Couture [ 2020-07-13 ]

Just resolved the issue with an sprintf
Been programming in PhP too long...
Thanks

Richard

Comment by Georg Richter [ 2020-07-13 ]

closed on user request

Generated at Thu Feb 08 03:05:39 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.