[odb-users] XML type for a class member using ODB and postgresql

Simón Emmanuel Gutiérrez Brida simon.gutierrez.brida at gmail.com
Wed Jan 29 13:13:21 EST 2014


Hi,

2014-01-29 Boris Kolpackov <boris at codesynthesis.com>

> Hi,
>
> Simón Emmanuel Gutiérrez Brida <simon.gutierrez.brida at gmail.com> writes:
>
> > #pragma db type("XML")
> > std::string data;
> >
> > But when I compile with odb I get
> >
> > error: unknown PostgreSQL type 'XML'
>
> In ODB database types like PG XML are called "extended database types"
> and are no mapped automatically (there are too many such types and
> different applications often require different mappings).
>
> Instead, what ODB does is provide a generic mechanism that allows
> you to map any extended database type to any C++ type via one of
> the "core database types" that are natively supported by ODB. This
> article describes this mechanism in detail:
>
>
> http://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/
>
> In your case, you can use TEXT as the core type and the mapping
> expression could look something like this (based on the PG docs,
> I haven't tested it myself):
>
> #pragma db map type("XML")       \
>                as("TEXT")        \
>                to("XMLPARSE(DOCUMENT (?))") \
>                from("XMLSERIALIZE(DOCUMENT (?) AS TEXT)")
>
> Let us know if this works for you.
>
> Boris
>


Using

#pragma db map type("XML")       \
               as("TEXT")        \
               to("XMLPARSE(DOCUMENT (?))") \
               from("XMLSERIALIZE(DOCUMENT (?) AS TEXT)")
#pragma db type("XML")
std::string data;

Appears to have solved the issue.


More information about the odb-users mailing list