List:MySQL++« Previous MessageNext Message »
From:Joel Fielder Date:March 29 2006 5:11pm
Subject:throw exceptions flag not properly copied in the copy constructor for mysqlpp::Query
View as plain text  
Hello,

I would like to highlight a possible bug according to the following
entry in the change log for version 2.0.0, 2005.08.16 (r1031) The
"Excess Hair Removal" release:

>The "throw exceptions" flag is passed from parent to child
>in all situations now.  (Or if not, please report it as
>a bug.) [snip]

Regards,
Joel.

-- Recreation (pseudo-ish) Code --

class crasher
{
public:
	crasher(const mysqlpp::Query& q);

	mysqlpp::Query m_query;
};

crasher::crasher(const mysqlpp::Query& q)
: m_query(q)
{
	std::cout << q.throw_exceptions() << std::endl;
	std::cout << m_query.throw_exceptions() << std::endl;
}

main()
{
	mysqlpp::Connection con("blah","blah","blah","blah");
	mysqlpp::Query q = con.query();

	crasher c(q);
	c.m_query << "select * from `non_existent_table`";

	try
	{
		std::vector<MY_SSQLS_STRUCT> res;
		c.m_query.storein(res);
	}
	catch(const std::exception& e)
	{
		std::cout << e.what() << std::endl;
	}
}

-- Expected Console Output --

1
1
Table 'non_existent_table' doesn't exist

-- Actual Console Output --

1
0
Segmentation fault

-- Solution --

I think that the copy constructor for mysqlpp::Query is copying the
wrong exceptions flag.

Therefore line 35 of query.cpp:

OptionalExceptions(q.exceptions()),

should be changed to read:

OptionalExceptions(q.throw_exceptions()),

which would match the behaviour of Query::operator=.

Thread
throw exceptions flag not properly copied in the copy constructor for mysqlpp::QueryJoel Fielder29 Mar
  • Re: throw exceptions flag not properly copied in the copy constructorfor mysqlpp::QueryWarren Young31 Mar