MySQL Forums
Forum List  »  Connector/C++

Re: Mysql connector c++ 8.0. How to work with datetime?
Posted by: Rafal Somla
Date: January 25, 2020 03:15AM

Hi Egor,

For some MySQL types, like numeric and string, we do conversions from MySQL representation to the corresponding C++ type, because the type to convert to is obvious in these cases. However, there are other MySQL types for which it is not so clear what C++ type should be used to represent the value, for example the DECIMAL type for fixed precision numbers (not that such types do not exist, but it is not clear if/which one should be supported). For the moment the situation we have is that for all MySQL value types that do not have the obvious automatic conversion to C++ type, user is responsible for converting it to the type of his choice. It can be done by asking the server to do the conversion (for example to string), like Luis has suggested. The other option is to get the raw binary representation of the value using Value::getRawBytes() and work with that, which of course requires understanding of how different types of MySQL values are represented in the protocol. For temporary types you can find this information here: <https://dev.mysql.com/doc/internals/en/x-protocol-messages-messages.html#x-protocol-messages-resultsets>;.

We believe that there is no single "right" way of representing the different possible values and in the end the user has to decide what exact representation to use. Certainly the task of converting the internal representation to user's type of choice could be made simpler, for example using template techniques, and we are thinking about such solutions. But at the moment the only way is to either look at the internal representation or ask server to do the conversion.

Options: ReplyQuote




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.