[odb-users] About MySQL type decimal

Boris Kolpackov boris at codesynthesis.com
Thu Feb 4 04:20:15 EST 2016


Hi Aarón,

Aarón Bueno Villares <abv150ci at gmail.com> writes:

> If I define the type of a field as a `DECIMAL(4, 2)` (for a MySQL engine),
> what must be the C++ type of that field, `string`, `float`/`double` or
> both? Because the docs says nothing about decimals.

Added to the manual:

"The only built-in mapping provided for the MySQL DECIMAL type is to
std::string/char[N], for example:


#pragma db object
class object
{
  ...

  #pragma db type ("DECIMAL(6,3)")
  std::string value_;
};
  

You can, however, map DECIMAL to a custom C++ type by providing a suitable
odb::mysql::value_traits specialization."


> Does ODB also test or round the value of the field?

No. It just puts whatever MySQL sent into the string and similarly sends
to  MySQL whatever you put into the string.

Boris



More information about the odb-users mailing list