dbTalk Databases Forums  

Wishlist item: Automatic conversion from ColData to bool

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Wishlist item: Automatic conversion from ColData to bool in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Byrial Jensen
 
Posts: n/a

Default Wishlist item: Automatic conversion from ColData to bool - 05-29-2005 , 12:47 PM






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
so I in my programs can write someting like:

Row row = result.fetch_row ();
bool my_bool = row[0];

Best regards,
Byrial

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Warren Young
 
Posts: n/a

Default Re: Wishlist item: Automatic conversion from ColData to bool - 06-01-2005 , 06:26 AM






Byrial Jensen wrote:

Quote:
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.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Byrial Jensen
 
Posts: n/a

Default Re: Wishlist item: Automatic conversion from ColData to bool - 06-01-2005 , 01:46 PM



Warren Young wrote:
Quote:
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;
};


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Warren Young
 
Posts: n/a

Default Re: Wishlist item: Automatic conversion from ColData to bool - 06-20-2005 , 04:55 AM



Byrial Jensen wrote:

Quote:
+ /// \brief Converts this object's string data to a bool
+ operator bool() const { return conv(0); }
+
Applied to v2.0 tree. Thanks!

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.