List:MySQL++« Previous MessageNext Message »
From:bsingh Date:June 3 2008 5:54am
Subject:Re: mysqlpp::Query Issue
View as plain text  
Hi Warren,

I was saying that if I declare  mysqlpp::Query sqlquery();   instead of     
mysqlpp::Query sqlquery = m_pCommon->commonDBCon.query();   then I was not able to use
'sqlquery' object  for another transaction. I tried to do it  again to see what happens
but it is not compiling because of  stream "<<" operation. 
Anyway, It seems all is fine  now and I also removed CriticalSection calls and now using
another Mutex object.  
SysMutex is predefined object which I have been using other places and destructor of this
class takes care of releasing. 

Here is  final code...

    SysMutex_var mutex = m_pCommon->m_mutexDBAccess;
    if (!mutex.waitForMutex(INFINITE))
        LOG_WARN(logger,"Tel_app::Load:Error getting mutex");
        return -1;
        // Load the app
        mysqlpp::Query sqlquery = m_pCommon->commonDBCon.query();
        mysqlpp::StoreQueryResult sqlresults;
        // Form query first        
        sqlquery << "select * from Applications where AppDN=" << AppDN; 
        sqlresults =;
        if(sqlresults) {
            //for (size_t i = 0; i < res.num_rows(); ++i) {  // one app only
                m_nAppDN   = sqlresults[0]["AppDN"];
                m_sAppName = sqlresults[0]["AppName"]; 
                m_sAppDesc = sqlresults[0]["AppDescription"];
        else {
            LOG_ERROR(logger,"Failed to get AppInfo");
            return -1;
        // Now, Load Application Steps
        sqlquery << "select * from ApplicationSteps where AppDN=" << AppDN; 
        sqlresults =;

        AppSteps_Module temp2;
        if (sqlresults) {
            for (size_t i = 0; i < sqlresults.num_rows(); ++i) {  
                temp2.StepNumber = sqlresults[i]["StepNumber"];
                int StepType = sqlresults[i]["StepType"];
                temp2.StepType = (Step_Type)StepType;
                temp2.PromptID= sqlresults[i]["PromptID"];
                temp2.PromptFileName  = sqlresults[i]["PromptFileName"];
                temp2.PromptText        = sqlresults[i]["PromptText"];
                temp2.MaxDigits        = sqlresults[i]["MaxDigits"];
                temp2.MaxSeconds        = sqlresults[i]["MaxSeconds"];
                temp2.TermTones        = sqlresults[i]["TermTones"];
                temp2.ValidDigits        = sqlresults[i]["ValidDigits"];

        else {
            LOG_ERROR(logger,"Failed to get AppSteps");
            return -1;

        // Now, Load Application Step Items 
        sqlquery << "select * from ApplicationStepItems where AppDN=" <<
        sqlresults =;
        AppStepItems_Module temp;
        if (sqlresults) {
            for (size_t i = 0; i < sqlresults.num_rows(); ++i) {  
                temp.StepNumber = sqlresults[i]["StepNumber"];
                temp.AppKeypadId = sqlresults[i]["AppKeypadId"];
                temp.NextStepNumber = sqlresults[i]["NextStepNumber"];
        else {
            LOG_ERROR(logger,"Failed to get AppStepItems");
            return -1;
    } // try
    catch (const mysqlpp::BadQuery& er) {
        // Handle any query errors
        LOG_ERROR(logger,"TelApp:Query error: " << er.what() );
        return -1;
    catch (const mysqlpp::BadConversion& er) {
        // Handle bad conversions; e.g. type mismatch populating 'stock'
        LOG_ERROR(logger,"TelApp:Conversion error: " << er.what() << "
tretrieved data size: " << er.retrieved <<", actual size: " <<
        return -1;
    catch (const mysqlpp::Exception& er) {
        // Catch-all for any other MySQL++ exceptions
        LOG_ERROR(logger,"TelApp:Exception: " << er.what() );
        return -1;
        LOG_ERROR(logger,"TelApp:Unknown Exception");
        return -1;

----- Original Message ----
From: Warren Young <mysqlpp@stripped>
To: MySQL++ Mailing List <plusplus@stripped>
Sent: Monday, June 2, 2008 2:00:44 AM
Subject: Re: mysqlpp::Query  Issue

onlyreply-sql@stripped wrote:
> I think the problem was with
> default constructor on query object not properly being initialized.
> Once I  initialized sqlquery object like this ... mysqlpp::Query
> sqlquery = commonDBCon.query(); , the problem went away 

Are you saying that it doesn't work when you pass the query string to 
Connection::query()?  The examples do this in several places 
successfully, and this is an intended feature, so if you can show an 
instance where it doesn't work, I'd be interested in seeing compilable 
code that shows it.

>             LeaveCriticalSection(&m_csDBAccess);

Not MySQL++ related, but this is highly error-prone code.  You should be 
using an RAII pattern here to make sure that all code paths that exit 
the function release the critical section mutex.  It appears fine now, 
but future maintenance could add a code path that accidentally doesn't 
release the mutex.  See the code for MySQL++'s Transaction class -- it's 
short -- for the general idea.

MySQL++ Mailing List
For list archives:
To unsubscribe:
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