MySQL Forums :: Connector/Arduino :: Using parameters


Advanced Search

Using parameters
Posted by: Peter Grimes ()
Date: February 22, 2014 12:33AM

Is it possible to use parameterised queries with the connector.

Eg:

Connector my_conn; // The Connector/Arduino reference

const char AddEvent[] = "INSERT INTO event (Record_Key, DateEntered, Point_ID, State, Message)
VALUES (:Record_Key, :DateEntered, :Point_ID, :State, :Message)";

// somehow set up my_conn for parameters
// I'm a delphi programmer so I will enter
// what I'm trying to say in delphi style

//-------------- start of sample

my_conn.query = "INSERT INTO event (Record_Key, DateEntered, Point_ID, State, Message) VALUES (:Record_Key, :DateEntered, :Point_ID, :State, :Message)"; // ADDEVENT Query
my_conn.prepare; // prepare the query

my_conn.ParamByName("Record_Key").value = "BGY000001"; // assign the record_key
my_conn.ParamByName("DateEntered").value = "2014/02/18 12:23:03"; // assign datetime
my_conn.ParamByName("Point_ID").value = 10; // assign point_id

// another way
my_conn.Param[3].value = 7; // assign state value
my_conn.Param[4].value = "Hot Water System 240V Bypass - ON"; // assing message

// execute the query
my_conn.ExecSql;

//-------------- end of sample

I would not expect this sort of functionalaty to work on a UNO, I am
targeting a DUE or MEGA

I hope you understand what I mean by the above.

I would also like to thank you for the work you have already done, it
is a fantasic effort.

I really think your onto something here, I store all the data I retrieve
from my arduinos into MYSQL. Currenty I do it through Delphi programs
by reading comm ports. With your connector I am hoping to get rid of the
PC's running my programs and do the saving directly from the arduino.

I am going to start converting to the arduino using the sprintf function
to build the query string but I would really love the Parameters way of
doing things.

Many thanks

Peter

Options: ReplyQuote


Subject Views Written By Posted
Using parameters 2647 Peter Grimes 02/22/2014 12:33AM
Re: Using parameters 1159 Noam Parness 02/26/2014 02:23PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.