List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:June 2 2008 12:27am
Subject:Re: mysqlpp::Query Issue
View as plain text  
(Something in the way you posted this message is messed up: all these  
 s make reading it a lot harder than it ought to be.  Please find  
and fix this problem.)

On Jun 1, 2008, at 3:47 AM, onlyreply-sql@stripped wrote:

> sqlresults.clear();

It's not necessary to clear() the query result object.

> sqlquery.reset();

This reset() call is either misplaced, or unnecessary.

MySQL++ v3 auto-resets the query object after a successful execution  
unless you're using template queries.

It doesn't auto-reset with template queries because that would throw  
away the template.  This doesn't apply here because you're not using  
that feature.

It also doesn't auto-reset after an error executing the query because  
some people like to send the failed SQL out to the debug log when  
reporting query errors.  Thus, if I'm wrong and reset() is somehow  
needed in your program, the bug may be that you have the reset() call  
inside the if { } statement: if the query fails, you need to reset()  
the query object before reusing it.

> sprintf(strquery,"select * from ApplicationStepItems where AppDN= 
> %d",nAppDN);

It's not relevant to your problem, but I wanted to point out that  
there's no need to build the query string separately here.  MySQL++  
has two built-in mechanisms for building query strings like this  
already: template queries, and a C++ stream interface.

Template queries are very much like sprintf(), but I think  
inappropriate in this particular instance.  They make the most sense  
when you re-use the same basic query format multiple times.  In your  
case, you're giving a different type of query each time.

I'd use the stream interface:

	Query q = conn.query("select * from ApplicationStepItems where  
	q << nAppDN;

This gives you several advantages.  You avoid the need for a temporary  
buffer, you avoid the possibility of a buffer overrun, you can use  
data types that sprintf() doesn't know how to cope with, and you get  
features like automatic quoting and escaping.

> mysqlpp::Query sqlquery2 = pSystem-&gt;m_pCommon- 
> &gt;commonDBCon.query(strquery);

Here we see that you're not reusing the Query object, so reset()  
cannot help.  Resetting the first Query object can't affect this one,  
even though they use the same Connection object.

> Can anyone please suggest me the solution ?

You haven't given enough information.  You just say it doesn't work,  
but don't give the error message. I may have accidentally hit on the  
solution above, but if you make all these changes and you still get  
the same problem, I wouldn't be surprised.  Post the error message  
you're getting.
MySQL example codejupiter.hce29 May
  • Re: MySQL example codeWarren Young29 May
  • mysqlpp::Query Issueonlyreply-sql1 Jun
    • Re: mysqlpp::Query IssueWarren Young2 Jun
Re: mysqlpp::Query Issueonlyreply-sql2 Jun
  • Re: mysqlpp::Query IssueWarren Young2 Jun
  • Re: mysqlpp::Query IssueAlexis Rodriguez Castedo2 Jun
Re: mysqlpp::Query Issuebsingh3 Jun