The mysqlpp::Query class member function str() returns a std::string
containing a null byte. I realize this is the actual documented
behavior of the function, but this runs contrary to the normal use of
std::string. Here is an example program:
#include <mysql++.h>
int
main()
{
mysqlpp::Connection c("s5db", "...", "root", "...");
mysqlpp::Query q = c.query();
std::cout << "preview length = " << q.preview().length() << std::endl;
std::cout << "preview[0] = " << q.preview().at(0) << std::endl;
return 0;
}
This code produces the following output:
$ foo
preview length = 1
preview[0] =
That is when a Query object is created the query length is non-zero
and actually contains a zero byte. The normal use of std::string is
to allow the string class itself to manage the termination of the
string. This is the documented behavior of std::string and allows
an implementation the freedom to use other termination techniques
(such as a length count).
The behavior of Query::str() thus interferes with normal usage of
std::strings. For example,
a) The length of an empty query is not zero
b) if I execute the following code:
std::string msg("query contains '" + q.preview() + "'");
There will be a null byte embedded in the single quoted string.
Is there any chance of altering the behavior of Query::str() to return
a more standard std::string?
Thanks,
Robert Mecklenburg
S5 Wireless, Inc.