[odb-users] Use of postgresql array mapping for native views

Lisa Fiedler lfiedler at informatik.uni-leipzig.de
Thu Apr 18 07:29:48 EDT 2019


Hello,

I was trying to use a postgresql array mapping to a vector within a 
native view.

That is I generated a file "traits-pgsql.hxx" with content:

#ifndef TRAITS_PGSQL_HXX #define TRAITS_PGSQL_HXX #include <cstddef> // 
std::size_t #include <cstring> // std::strncmp, std::memset, std::memcpy 
#include <iostream> #include <fstream> #include <odb/pgsql/traits.hxx> 
#include <odb/pgsql/details/endian-traits.hxx> #include 
"../configdb.hpp" #include <ctime>   // localtime, mktime, time_t, tm 
#include <sstream> namespace odb {   namespace pgsql   {     template <> 
     class value_traits<std::vector<u_int64_t>, id_string>     {     
public:       typedef std::vector<u_int64_t> value_type;       typedef 
value_type query_type;       typedef details::buffer image_type;       
static void       set_value (value_type& v,                  const 
details::buffer& b,                  std::size_t n,                  
bool is_null)       {         v.clear ();         if (!is_null)         
{           char c;           std::istringstream is (std::string (b.data 
(), n));           is >> c; // '{'           for (c = static_cast<char> 
(is.peek ()); c != '}'; is >> c)           {             v.push_back 
(u_int64_t ());             is >> v.back ();           }         }       
}       static void       set_image (details::buffer& b, 
                  std::size_t& n,                  bool& is_null, 
                  const value_type& v)       {         is_null = false; 
         std::ostringstream os;         os << '{';         for 
(value_type::const_iterator i (v.begin ()), e (v.end ());              i 
!= e;)         {           os << *i;           if (++i != e)             
os << ',';         }         os << '}';         const std::string& s 
(os.str ());         n = s.size ();         if (n > b.capacity ()) 
           b.capacity (n);         std::memcpy (b.data (), s.c_str (), 
n);       }     };   } } #endif // TRAITS_PGSQL_HXX

and in taxonomy.hxx, where I was planning to use this mapping I wrote:

typedef std::vector<u_int64_t> id_vector; #pragma db value(id_vector) 
type("BIGINT[]")

and tried to use this in a native query like this:

#pragma db view struct queryTaxonomyPath_view{     #pragma db 
type("BIGINT[]")     id_vector path; };

The error message I get is:

./include/complete/taxonomy.hxx:241:15: error: invalid PostgreSQL type 
declaration: unexpected character '['

Makefile:60: recipe for target 'include/complete/taxonomy-odb.cxx' failed

make: *** [include/complete/taxonomy-odb.cxx] Error 1

make: *** Waiting for unfinished jobs....

./include/complete/taxonomy.hxx:241:15: error: invalid PostgreSQL type 
declaration: unexpected character '['

terminate called after throwing an instance of 'cutl::fs::error'

what(): filesystem error

*** WARNING *** there are active plugins, do not report this as a bug 
unless you can reproduce it without enabling any plugins.

Event | Plugins

PLUGIN_START_UNIT | odb

PLUGIN_PRAGMAS | odb

PLUGIN_OVERRIDE_GATE | odb

In file included from 
/usr/local/odb-2.5.0-b.13/libodb/include/odb/container-traits.hxx:217:0,

from <standard-odb-epilogue>:4:

/usr/local/odb-2.5.0-b.13/libodb/include/odb/std-unordered-set-traits.hxx: 
In function ‘void __static_initialization_and_destruction_0(int, int)’:

/usr/local/odb-2.5.0-b.13/libodb/include/odb/std-unordered-set-traits.hxx:122:1: 
internal compiler error: Aborted

}

^

To generate the *odb.ixx and *odb.cxx files I used:

/usr/local/odb-2.5.0-b.13/odb/bin/odb -d pgsql 
-I/usr/local/odb-2.5.0-b.13/libodb/include --std c++11 --generate-query 
--generate-prepared --hxx-prologue "#include \"traits-pgsql.hxx\"" 
./include/complete/properties.hxx ./include/complete/structures.hxx 
./include/complete/taxonomy.hxx ./include/complete/edge.hxx 
./include/complete/record.hxx

If I remove the native view there are no error messages.

Thank you in advance!



More information about the odb-users mailing list