Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
Query::str returns std::string containing null

Query::str returns std::string containing null

2007-01-08       - By Robert Mecklenburg

 Back
Reply:     1     2     3  

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.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:    http://lists.mysql.com/plusplus?unsub=mysql@(protected)