List:MySQL++« Previous MessageNext Message »
From:Byrial Jensen Date:June 1 2005 6:46pm
Subject:Re: Wishlist item: Automatic conversion from ColData to bool
View as plain text  
Warren Young wrote:
> Byrial Jensen wrote:
> 
>> I often store booleans (MySQL type BOOL, alias for TINYINT(1)). So it 
>> would be very nice to have an automatic conversion from ColData to bool 
> 
> Unless I'm greatly mistaken, this would be a pretty trivial thing to 
> patch; 3 lines in coldata.h, probably.  Congratulations, you're 
> volunteered.  :)

You are of course right that it can be done in 3 lines. It would herpaps 
be more elegant to make a new variant of mysql_convert() instead of 
relying on C++'s implicit conversion from int to bool, but here it is.

Best regards,
Byrial

--- coldata.h~  2005-06-01 20:36:20.574670267 +0200
+++ coldata.h   2005-06-01 20:37:45.324233098 +0200
@@ -205,6 +205,9 @@ public:
         /// \brief Converts this object's string data to a double
         operator double() const { return conv(static_cast<double>(0)); }

+       /// \brief Converts this object's string data to a bool
+       operator bool() const { return conv(0); }
+
         template <class T, class B> operator Null<T, B>() const;
  };

Thread
Wishlist item: Automatic conversion from ColData to boolByrial Jensen29 May
  • Re: Wishlist item: Automatic conversion from ColData to boolWarren Young1 Jun
    • Re: Wishlist item: Automatic conversion from ColData to boolByrial Jensen1 Jun
      • Re: Wishlist item: Automatic conversion from ColData to boolWarren Young20 Jun