List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:June 30 2008 8:35am
Subject:Re: sql_create_ macro
View as plain text  
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 <mysql++.h>
#include <ssqls.h>
#include <iostream>

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...
Thread
sql_create_ macroSoul Boy13 Jun
  • Re: sql_create_ macroWarren Young13 Jun
    • Re: sql_create_ macroGareth Pidgeon18 Jun
      • Re: sql_create_ macroWarren Young22 Jun
Re: sql_create_ macroSoul Boy23 Jun
  • Re: sql_create_ macroWarren Young27 Jun
Re: sql_create_ macroSoul Boy30 Jun
  • Re: sql_create_ macroWarren Young30 Jun
Re: sql_create_ macroSoul Boy30 Jun