We finally are getting time to upgrade MySQL++ from 2.3.2 and having some conversion
pains. I'm getting through most of them but am kinda stuck on this one.
We often setup the parameters for a template query ahead of time and pass no parameters to
store(). With 3.08 we're getting errors due to what looks like a substitution bug. I
took the tquery1 sample and modified it slightly (see below) so you can reproduce the
problem.
This is around line 48 of tquery1.cpp (my changes marked <<<<<). Note that
using a numeric parameter instead of a string (as in this example) makes a difference
since using a string is syntactically valid SQL, but returns nothing since the string is
wrong. If the parameter is numeric, you get a BadQuery exception.
// Build a template query to retrieve a stock item given by
// item name.
mysqlpp::Query query = con.query(
"select * from stock where item = %0q");
query.parse();
query.template_defaults[0U] = "Nürnberger Brats"; // <<<<< set
default value
// Retrieve an item added by resetdb; it won't be there if
// tquery* or ssqls3 is run since resetdb.
mysqlpp::StoreQueryResult res1 = query.store(); // <<<<< removed param
You get nothing back due to badly formed query. It looks like the problem is that str()
is executed twice during the call the query.store(). First by the query::store() (no
params):
>>from query.h
StoreQueryResult store() { return store(str(template_defaults)); }
This str() returns the query with the parameter in place:
"select * from stock where item = 'Nürnberger Brats'"
But then later str() is called again from store(SQLQueryParms& p):
>>from query.cpp
StoreQueryResult
Query::store(SQLQueryParms& p)
{
AutoFlag<> af(template_defaults.processing_);
return store(str(p));
}
After this second str(), the query looks like this:
"select * from stock where item = 'select * from stock where item =
\'Nürnberger Brats\''"
I'd take a whack at a fix, but I'm not sure what would be correct.