List:MySQL++« Previous MessageNext Message »
From:Joel Fielder Date:January 7 2010 1:15pm
Subject:Query::execute crashes without a connected driver
View as plain text  
Hi Warren,

I'm on v3.0.8 at the moment, the following will crash:

mysqlpp::Connection database;
mysqlpp::Query mysql = database.query();
mysql << "SELECT * FROM `test`";
mysql.execute();

This may be expected behaviour, but if throw_exceptions is true it still 
crashes where I'd expect an exception.  Would you agree?  Below is my 
version of execute, but I wasn't sure of what should happen to 
copacetic_ flag or which exception would be most appropriate to throw!  
I've also made it return SimpleResult() if not connected but maybe you 
still want it to break?

SimpleResult
Query::execute(const char* str, size_t len)
{
    if(conn_->driver()->connected() == false)
    {
        if(throw_exceptions())
            throw(std::logic_error("You can't execute a query unless 
you're connected"));
        return SimpleResult();
    }

    if ((copacetic_ = conn_->driver()->execute(str, len)) == true) {
        if (parse_elems_.size() == 0) {
            // Not a template query, so auto-reset
            reset();
        }
        return SimpleResult(conn_, insert_id(), affected_rows(), info());
    }
    else if (throw_exceptions()) {
        throw BadQuery(error(), errnum());
    }
    else {
        return SimpleResult();
    }
}

Joel

-- 
Joel Fielder

T: 01323 649779
F: 01323 644999
W: www.switchplane.com
A: 19 The Avenue
   Eastbourne
   BN21 3YD
   
Switchplane Ltd is registered in England and Wales with company number 04840582,
registered office 61 Brassey Avenue, Eastbourne, BN22 9QH.

Our VAT registration number is 819 5635 01 and we are registered as a data controller with
the Information Commissioner, registration number Z8542239.

Thread
Query::execute crashes without a connected driverJoel Fielder7 Jan
  • Re: Query::execute crashes without a connected driverWarren Young7 Jan
    • Re: Query::execute crashes without a connected driverJoel Fielder8 Jan
    • mysqlpp::ScopedConnectionJoel Fielder8 Jan
      • Re: mysqlpp::ScopedConnectionWarren Young9 Jan
        • Re: mysqlpp::ScopedConnectionJonathan Wakely9 Jan
          • Re: mysqlpp::ScopedConnectionJoel Fielder11 Jan
            • Re: mysqlpp::ScopedConnectionJonathan Wakely11 Jan
              • Re: mysqlpp::ScopedConnectionWarren Young11 Jan
                • Re: mysqlpp::ScopedConnectionJonathan Wakely11 Jan
    • Re: Query::execute crashes without a connected driverJoel Fielder13 Jan
      • Re: Query::execute crashes without a connected driverWarren Young13 Jan
Re: mysqlpp::ScopedConnectionJoel Fielder11 Jan
  • Re: mysqlpp::ScopedConnectionWarren Young11 Jan
    • Re: mysqlpp::ScopedConnectionJoel Fielder11 Jan
      • Re: mysqlpp::ScopedConnectionWarren Young11 Jan
        • Re: mysqlpp::ScopedConnectionJoel Fielder12 Jan