MySQL Forums
Forum List  »  Connector/C++

Re: Prepared queries in Connector C++
Posted by: James Cooper
Date: April 20, 2023 10:37AM

OK, I figure it out. This works for any query, and you can rerun it with new parameters without recompiling it. You set the parameters in the order they appear in the query. Sorry that this forum does not have a code display setting:


string sql = "Select distinct foodname, price, storename from prices \
join foods on(foods.foodkey = prices.foodkey) \
join stores on(stores.storekey = prices.storekey) \
where price > ? and storename like ?";

//bind two parameters to the query
SqlStatement query = session.sql(sql);
float pval = 2.0;
query.bind(pval);
query.bind("V%");

SqlResult res = query.execute();

Options: ReplyQuote


Subject
Views
Written By
Posted
200
April 20, 2023 06:41AM
Re: Prepared queries in Connector C++
117
April 20, 2023 10:37AM


Sorry, only registered users may post in this forum.

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.