List:MySQL++« Previous MessageNext Message »
From:Jim Wallace Date:January 28 2009 12:27am
Subject:RE: query.str() in template query -- <blush>
View as plain text  
I just read this in the manual regarding calling it with no parameters:

"This can work, but it is not designed to. In fact, it's known to fail horribly in one
common case. You will not get sympathy if you complain on the mailing list about it not
working. If your code doesn't actively reuse at least one of the parameters in subsequent
queries, you're abusing MySQL++, and it is likely to take its revenge on you."

It'd be cool if this abuse could be detected at compile time instead of runtime.  I see
the same comment in the 2.3.2 doc, so I've just be a lucky dog until now.

-----Original Message-----
From: Jim Wallace [mailto:jwallace@stripped] 
Sent: Tuesday, January 27, 2009 7:02 PM
To: plusplus@stripped
Subject: query.str() in template query -- help!

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.

-- 
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:    http://lists.mysql.com/plusplus?unsub=1


Thread
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