[odb-users] Compilation error when using decimal(p, s) or bytea types

Sam lists1 at afach.de
Sun Mar 24 12:12:51 EDT 2019


   Thank you for the response, Boris.

   There's an issue that's I still don't understand. From reading that
   blog post, I understand how conversions are done on a low level by
   implementing value_traits template. So I can convert directly from my
   type to details::buffer back and forth, which will be stored directly
   in my database as is. This seems perfect for blobs and byte-arrays and
   other non-numeric types. But for decimal, I don't understand how this
   works. I don't know how PostgreSQL stores decimal/numeric internally
   (and for cross-platform compatibility I'm avoiding guessing). When
   using SQL queries to store decimal, the decimal value is provided as
   normal numbers, e.g., "1.2345". How can I do the same with ODB?

   In other words: If my decimal number is in an std::string in ASCII
   form, how will the function set_image() look like?

   I don't imagine I can just use memcpy there because that won't do any
   binary encoding.

   Can you please provide an example on how to write set_image correctly
   for decimal/numeric type from std::string in ASCII format, so that
   database table-viewers can interpret them correctly?

   Best,

   Sam

   On 2019-03-24 2:03 PM, Boris Kolpackov wrote:

Sam [1]<lists1 at afach.de> writes:

   #ifdef ODB_COMPILER
   #pragma db default("0") column("Balance") type("decimal(8,8)")
   #endif
       std::string balance;

   The error is the following:

   /home/user/temp/build-odb_test-Default_cmake-Default/OrmBalancesClass_
   ODB_generated/OrmBalances-odb.cxx:206: error: too many arguments to
   function call, expected 3, have 4; did you mean
   'pgsql::c_string_value_traits::set_image'?
         pgsql::value_traits<
         ^~~~~
         pgsql::c_string_value_traits::set_image

   Is this a bug or am I doing something wrong?

There is no built-in mapping for Postgres decimal type to std::string.
All the available built-in mappings are described in the manual,
specifically, Section 19.1, "PostgreSQL Type Mapping". You can also
add support for a custom mapping as described in this blog post:

[2]https://www.codesynthesis.com/~boris/blog/2012/10/16/custom-cxx-to-database-
type-mapping-in-odb/

References

   1. mailto:lists1 at afach.de
   2. https://www.codesynthesis.com/~boris/blog/2012/10/16/custom-cxx-to-database-type-mapping-in-odb/


More information about the odb-users mailing list