List:MySQL++« Previous MessageNext Message »
From:Jim Wallace Date:January 28 2009 12:02am
Subject:query.str() in template query -- help!
View as plain text  
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

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.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 =; // <<<<< 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  First by the query::store() (no

>>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
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.
RELEASE: v3.0.5Warren Young7 Aug
  • query.str() in template query -- help!Jim Wallace28 Jan
    • RE: query.str() in template query -- <blush>Jim Wallace28 Jan
      • Re: query.str() in template query -- <blush>Warren Young28 Jan
        • storein with parametersJim Wallace28 Jan
          • Re: storein with parametersWarren Young28 Jan
            • RE: storein with parametersJim Wallace28 Jan
              • Re: storein with parametersWarren Young28 Jan
            • Question about BadQueryJim Wallace28 Jan
              • Re: Question about BadQueryWarren Young28 Jan
RE: RELEASE: v3.0.5Bernard8 Aug
  • Re: RELEASE: v3.0.5Warren Young8 Aug
    • Re: RELEASE: v3.0.5Alex9 Aug
RE: Question about BadQueryJim Wallace28 Jan
RE: Question about BadQueryDale Stewart28 Jan
RE: Question about BadQueryDale Stewart28 Jan
  • Re: Question about BadQueryWarren Young28 Jan