List:MySQL++« Previous MessageNext Message »
From:Soul Boy Date:June 30 2008 12:04pm
Subject:Re: Status of mysqlpp::Null in ssqls
View as plain text  
Hi I can understand what your saying however from a users/usability
point of view it would be intuitive and useful if there was someway of
doing this other than declaring all your macros as nulls just in case
you want to insert a null value sometimes.

Thanks

2008/6/30 Warren Young <mysqlpp@stripped>:
> 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.
>
> --
> MySQL++ Mailing List
> For list archives: http://lists.mysql.com/plusplus
> To unsubscribe:
>  http://lists.mysql.com/plusplus?unsub=1
>
>
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