From: Warren Young Date: June 30 2008 8:35am Subject: Re: sql_create_ macro List-Archive: http://lists.mysql.com/plusplus/7716 Message-Id: <97CD9474-A233-4436-8E62-6968A2508340@etr-usa.com> MIME-Version: 1.0 (Apple Message framework v924) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Jun 29, 2008, at 8:02 PM, Soul Boy wrote: > This goes in a file called Test.h ...cut...paste...hack... The problem can be demonstrated with much fewer lines: ---------- 8< -------- cut here --------- 8< ----------- #include #include #include sql_create_1(Test, 1, 0, mysqlpp::String, A); int main() { std::string a("foo"); Test newRow(mysqlpp::String(a)); std::cout << newRow.table() << std::endl; return 0; } ---------- 8< -------- cut here --------- 8< ----------- This isn't specific to table(). You can get the same error trying to print out newRow.A. It's unrelated to Query, too. Query::insert() merely accesses elements of the SSQLS. It's probably not a compiler bug: I've seen essentially the same error in g++ 4.0, g++ 4.2, plus VC++ 2008. If you change the first two lines of main() to: Test newRow(mysqlpp::String(std::string("foo"))); ...the error goes away. (That is, make the temporary string implicit.) I don't think this is a MySQL++ problem. It feels like some weird C++ parsing issue. Since multiple new-model compilers give the same error, it's probably a "feature" of C++ in some demented way. Unless you're using BLOBs, this problem is easily fixed: use std::string in your SSQLSes, not mysqlpp::String. As it says in the docs, mysqlpp::String is not a general-purpose string type. The only reason end-user code should ever see mysqlpp::String directly is in dealing with BLOBs. If you are indeed using BLOBs, you can probably work around the problem by reordering the parameters in your SSQLS. I found it to happen with mysqlpp::DateTime, too, when that's first in the SSQLS. But, you'll notice that examples/stock.h doesn't give this error, since the sdate member is second to last. More generally, you should be using the data types in lib/sql_types.h when defining SSQLSes. So, mysqlpp::sql_blob instead of mysqlpp::String, mysqlpp::sql_char instead of std::string...