Closed Sebenzouz closed 5 years ago
The reason it isn't working is because you cannot use double, float, etc. with sprintf() in Arduino. You must use dtostrf() for the double to make it a string then pass it to sprintf(). See the complex_insert example sketch for an example. Also, see the dtostr() documentation.
char longstr[30]; long long id = 1231231; char INSERT_DATA1[] = "INSERT INTO arduilog.logs (id,subsystem,value) VALUES (%s,'%s','%s')"; ... dtostrf(id, 4, 4, longstr); sprintf(query1, INSERT_DATA1, longstr, message, autre);
Thank you so much you were right, my program is working now! Have a nice day!
You're welcome. :)
On 5/29/19 10:14 AM, Sebenzouz wrote:
Thank you so much you were right, my program is working now§ Have a nice day!
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/103?email_source=notifications&email_token=AB6SHYFQ6VHFJSYHKBBIMKTPX2FVNA5CNFSM4HQCUH32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWPO6JI#issuecomment-496955173, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6SHYHJTUNTQZQLKF5QBTDPX2FVNANCNFSM4HQCUH3Q.
Hi, Is it possible to put char content in sentences with sprintf() ? I would like an use like that (the actual code doesn't work, this is just to illustrate) :
char query1[128];
char message[]="hello";
char autre[]="world";
long long id=0;
char INSERT_DATA1[] = "INSERT INTO arduilog.logs (id,subsystem,value) VALUES (%d,'%s','%s')";
sprintf(query1, INSERT_DATA1,id,message,autre);
And if I printed query1 on the monitor, I would like to have a result like that:
INSERT INTO arduilog.logs (id,subsystem,value) VALUES (0,'hello','world')
Thanks.