5 messages in com.mysql.lists.plusplusRe: conversion from ‘mysqlpp::Query’ ...
FromSent OnAttachments
Dustin Moore02 Apr 2008 21:22 
Warren Young03 Apr 2008 16:11 
Dustin Moore03 Apr 2008 20:17.cpp
Warren Young08 Apr 2008 14:12 
Dustin Moore10 Apr 2008 20:10 
Subject:Re: conversion from ‘mysqlpp::Query’ to ‘bool’ is ambiguous
From:Warren Young (mysq@etr-usa.com)
Date:04/03/2008 04:11:29 PM
List:com.mysql.lists.plusplus

Dustin Moore wrote:

../DataInterface/DataInterface.cpp:100: error: conversion from ‘mysqlpp::Query’ to ‘bool’ is ambiguous /usr/local/include/mysql++/query.h:257: note: candidates are: mysqlpp::Query::operator bool mysqlpp::Query::*() const /usr/include/c++/4.1.3/bits/basic_ios.h:107: note: std::basic_ios<_CharT, _Traits>::operator void*() const [with _CharT = char, _Traits = std::char_traits<char>]

Well, this bug slipped through because what you're trying to do isn't idiomatic MySQL++. The standard way to test for query success is to test the execute() (or store(), or use(), or...) statement in bool context. Or, use exceptions. See the examples.

Nevertheless, it does need to be addressed. We have two options:

1. Avoid breaking the ABI by putting Query::success() back (maybe with a different name), it being an alias for the current bool conversion.

2. Remove the current bool conversion operator, and override basic_ios<>::operator void*() instead. This breaks the ABI and ignores warnings set down in the "safe bool" article that motivated adding this method to begin with. But, if the "right way" doesn't work, and this does...

I said I didn't want to break the ABI again, but it's still not long after the initial release, and it's a real design flaw.

Comments, anyone?

As a side note, I tried to use query.affected_rows() to determine a successful update, but the function returned a very large number(garbage) instead of -1 or 0, which would make more sense in context.

Works here.

Query::affected_rows() is a pretty thin wrapper over the C API: there are some indirections before you get down to the C API, but the number the C API returns is coming through untouched. Can you modify one of the examples to show the problem? I did it for examples/ssqls2.cpp, putting the call between the execute() and print_stock_rows() calls, and got 1, as expected.