Unable to retrieve a BIT column without explicit casting
Posted by: Michael Rubin
Date: June 25, 2013 09:48PM

Hello and thank you for your time.

I'm trying this on MySQL community 5.6.12 x64 on CentOS release 6.3 (Final).

I'm retrieving a result of a simple query (i.e. "SELECT * FROM MyTable") where one of the columns happens to be of type BIT(1). I noticed that when I cast the resulting row (from a particular MYSQL_ROW) to an std::string, I always get an empty string even when the bit should be a 1. (The length of that field always returns 1.) I tried treating the field as binary and doing something like: char c = *(row); but I still couldn't get a 1.

When I do an explicit cast, like "SELECT *,CAST(MyBitField AS UNSIGNED) AS MyBitField2 FROM MyTable", I get a 1 in my std::string from the additional row[].

Is there any way to get a 0 or 1 from a BIT column without this explicit cast?

Thanks.

Options: ReplyQuote


Subject
Views
Written By
Posted
Unable to retrieve a BIT column without explicit casting
2898
June 25, 2013 09:48PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.