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;

SqlResult res = query.execute();

Options: ReplyQuote

Written By
April 20, 2023 06:41AM
Re: Prepared queries in Connector C++
April 20, 2023 10:37AM

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.