List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:June 30 2008 11:52am
Subject:Re: Status of mysqlpp::Null in ssqls
View as plain text  
On Jun 30, 2008, at 3:59 AM, Soul Boy wrote:

> Should I be able to do this ?:
>
>     mysqlpp::Null<mysqlpp::sql_tinyint_unsigned> nullString;
>
>     Test newRow (nullString, 1);

No, you can't, on purpose.

If it did compile, it wouldn't work sensibly, for a couple of reasons.

If we take your code literally -- as the compiler will -- nullString  
isn't initialized.  Therefore, nullString.data also has no value, so  
newRow.A will get an undefined value.

If we instead assume that nullString *did* get initialized between  
your two lines of code, your declaration says it could be a SQL null,  
so you'd again get undefined in newRow.A.

It's easy to make the code compile:

     Test newRow(nullString.data, 1);

But this only makes sense if you know in advance that nullString is  
initialized with something other than SQL null.  In that case, I  
wonder why you are wrapping that data member in template Null to begin  
with.

You *can* do the inverse of what you asked:

     sql_create_2(Test2,
          1, 2,
          mysqlpp::Null<mysqlpp::sql_tinyint_unsigned>, A,
          mysqlpp::Null<mysqlpp::sql_tinyint_unsigned>, B)

     Test2 newRow2(nullString, 1);

Conversion this direction works because it never loses data.  It's  
much the same thing as type promotion in C++: you can assign a char to  
an int and always get sensible results.
Thread
Status of mysqlpp::Null in ssqlsSoul Boy30 Jun
  • Re: Status of mysqlpp::Null in ssqlsWarren Young30 Jun
    • Re: Status of mysqlpp::Null in ssqlsSoul Boy30 Jun
      • Re: Status of mysqlpp::Null in ssqlsWarren Young30 Jun
        • Re: Status of mysqlpp::Null in ssqlsSoul Boy1 Jul