[Libpqxx-general] Dealing with resultsets that include user-defined-types

Maurice Gittens mainmanmauricio at gmail.com
Fri May 22 06:30:45 UTC 2009


Hi all,


On Sat, Apr 25, 2009 at 9:16 AM, Jeroen Vermeulen <jtv at xs4all.nl> wrote:

> Maurice Gittens wrote:
>
>  This should help me to do the trick.
>>
>
> BTW please post any feedback you may have on this API.  Daniel Frey did
> some splendid work on it, and if you feel it's fit for practical third-party
> use I'd like to move it out of the pqxx::internal namespace.
>
>

Based on the recipe you provided, I tried implementing support for using a
user defined type as:

   my_udt o = resultset[0][0].as<my_udt>();


All I did was to provide a specialization for 'my_udt' along the lines you
suggested.

namespace pqxx
{
    template<> struct string_traits<my_udt>
    {
        static const char *name();
        static bool has_null();
        static bool is_null(const my_udt& o);
        static my_udt null();

        static void from_string(const char input[], my_udt& o);

        static std::string to_string(const my_udt& o);
    };
}

and it all worked without any noteworthy incidents; with the possible
exception that I think I needed to implement the above
in the pqxx namespace to avoid compile errors IIRC.

Kind regards,
Maurice



>
> Jeroen
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://pgfoundry.org/pipermail/libpqxx-general/attachments/20090522/5f57ba9b/attachment.html 


More information about the Libpqxx-general mailing list